Replace Mock API responses with pre_http_request filter#474
Conversation
…ttp_request-filter
…ttp_request-filter
…ttp_request-filter
There was a problem hiding this comment.
Pull request overview
This PR standardizes test-time API mocking by replacing the Mockoon-based mock server with a WordPress fixture plugin that intercepts BeyondWords API calls via the pre_http_request filter, enabled by the BEYONDWORDS_MOCK_API flag across CI and local environments.
Changes:
- Enable
BEYONDWORDS_MOCK_APIacross PHPUnit, wp-env, and GitHub Actions; remove Mockoon CLI usage. - Add a fixture plugin (
beyondwords-mock-rest-api-responses) to mock BeyondWords REST API responses during tests. - Update PHPUnit/Cypress setup to load/activate the mock plugin and adjust tests to use
Environment::getApiUrl().
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Removes Mockoon CLI dependency tree and related packages. |
| tests/phpunit/bootstrap.php | Defines BEYONDWORDS_MOCK_API before WP boots and loads the mock plugin after WP bootstrap. |
| tests/phpunit/Core/EnvironmentTest.php | Updates API URL expectation to match Environment::getApiUrl() behavior. |
| tests/phpunit/Core/ApiClientTest.php | Uses Environment::getApiUrl() instead of a global constant. |
| tests/fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php | Adds the WP-based mock API implementation using pre_http_request. |
| tests/fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/languages.json | Adds a language fixture dataset used by the mock plugin. |
| tests/cypress/e2e/settings/credentials/credentials.cy.js | Updates comment to refer to the new mock API approach. |
| package.json | Removes Mockoon CLI devDependency and script. |
| doc/running-tests.md | Updates local instructions to enable mock mode via .wp-env.override.json. |
| cypress.env.json.example | Updates example apiUrl value. |
| cypress.config.js | Activates the mock plugin during Cypress DB setup. |
| .wp-env.override.json.example | Adds BEYONDWORDS_MOCK_API config example. |
| .wp-env.json | Enables mock mode for wp-env test config. |
| .github/workflows/main.yml | Removes Mockoon startup, enables mock mode in wp-config, installs/activates the mock plugin, and adjusts Cypress env wiring. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Outdated
Show resolved
Hide resolved
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 15 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Outdated
Show resolved
Hide resolved
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Outdated
Show resolved
Hide resolved
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Outdated
Show resolved
Hide resolved
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 16 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/mock-rest-api-responses.php
Show resolved
Hide resolved
tests/fixtures/wp-content/plugins/beyondwords-mock-rest-api-responses/languages.json
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 16 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request refactors the test and development environment setup to remove the dependency on the external Mockoon mock API server. Instead, it enables a built-in mock API mode via the
BEYONDWORDS_MOCK_APIconfiguration, updates related documentation and scripts, and improves plugin installation in CI. The changes streamline local and CI testing, making the workflow more reliable and easier to maintain.Test and Environment Configuration:
BEYONDWORDS_API_URLenvironment/config variable withBEYONDWORDS_MOCK_API, enabling a built-in mock API mode for tests and local development (.github/workflows/main.yml,.wp-env.json,.wp-env.override.json.example,doc/running-tests.md,cypress.env.json.example) [1] [2] [3] [4] [5]..github/workflows/main.yml,package.json,doc/running-tests.md) [1] [2] [3] [4] [5].CI/CD Workflow Improvements:
.github/workflows/main.yml) [1] [2] [3]..github/workflows/main.yml,cypress.env.json.example) [1] [2] [3].Test Code and Plugin Activation:
beyondwords-mock-rest-api-responsesplugin is activated during Cypress and PHPUnit test setup (cypress.config.js,.github/workflows/main.yml) [1] [2] [3].tests/cypress/e2e/settings/credentials/credentials.cy.js).Code Quality and Maintainability:
src/Component/Post/GenerateAudio/index.jsfor clarity and maintainability.