Skip to content

Replace Mock API responses with pre_http_request filter#474

Merged
galbus merged 32 commits intomainfrom
s-6180-replace-mock-api-responses-with-pre_http_request-filter
Mar 11, 2026
Merged

Replace Mock API responses with pre_http_request filter#474
galbus merged 32 commits intomainfrom
s-6180-replace-mock-api-responses-with-pre_http_request-filter

Conversation

@galbus
Copy link
Copy Markdown
Contributor

@galbus galbus commented Dec 15, 2025

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_API configuration, 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:

  • Replaces usage of the BEYONDWORDS_API_URL environment/config variable with BEYONDWORDS_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].
  • Removes Mockoon CLI from CI workflows and project dependencies, including related scripts and documentation references (.github/workflows/main.yml, package.json, doc/running-tests.md) [1] [2] [3] [4] [5].

CI/CD Workflow Improvements:

  • Updates plugin installation steps in CI to handle both single-file and multi-file plugins, and ensures the mock REST API plugin is installed and activated for tests (.github/workflows/main.yml) [1] [2] [3].
  • Sets the correct environment variables for PHPUnit and Cypress, and updates the default API URL for Cypress tests (.github/workflows/main.yml, cypress.env.json.example) [1] [2] [3].

Test Code and Plugin Activation:

  • Ensures the beyondwords-mock-rest-api-responses plugin is activated during Cypress and PHPUnit test setup (cypress.config.js, .github/workflows/main.yml) [1] [2] [3].
  • Updates a Cypress test comment to reflect the new mock API behavior (tests/cypress/e2e/settings/credentials/credentials.cy.js).

Code Quality and Maintainability:

  • Refactors category matching logic in src/Component/Post/GenerateAudio/index.js for clarity and maintainability.

@galbus galbus self-assigned this Dec 15, 2025
@galbus galbus added enhancement php Pull requests that update Php code labels Dec 15, 2025
@linear
Copy link
Copy Markdown

linear bot commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_API across 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants