Skip to content

Build/Test Tools: Mock the external HTTP requests in the block patterns controller tests. - #13556

Closed
adimoldovan wants to merge 2 commits into
WordPress:trunkfrom
adimoldovan:63914-rest-block-patterns
Closed

adimoldovan wants to merge 2 commits into
WordPress:trunkfrom
adimoldovan:63914-rest-block-patterns

Conversation

@adimoldovan

@adimoldovan adimoldovan commented Sep 16, 2026

Copy link
Copy Markdown

Trac ticket: core.trac.wordpress.org/ticket/63914

Mock the pattern directory requests in Tests_REST_WpRestBlockPatternsController::test_get_items() and test_get_items_migrate_pattern_categories() with pre_http_request and move them out of the external-http group. The tests assert only on patterns in the test registry. They never checked remote patterns, and a failed request left the assertions unchanged, so the mock loses no coverage.

Testing Instructions

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --group external-http. Expect 84 tests and no failures.
  3. Run npm run test:php -- --exclude-group external-http tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php. Expect 12 tests and no failures.
  4. Confirm the mock keeps the tests off the network. Remove the two add_filter( 'pre_http_request', ... ) lines and run step 3 again. Expect two failures that name the api.wordpress.org URLs. Restore the lines.
  5. Check the coding standards: composer lint tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5.1
Used for: Verifying the mock against the live code path, running the test suites.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…ns controller tests.

Answer the pattern directory requests in `test_get_items()` and `test_get_items_migrate_pattern_categories()` with an empty response through `pre_http_request`, and move both tests out of the `external-http` group.

The tests assert only on patterns in the test registry. They never checked remote patterns, and a failed request left the assertions unchanged. The mock removes the network and keeps the coverage.
@adimoldovan adimoldovan self-assigned this Sep 16, 2026
@adimoldovan
adimoldovan marked this pull request as ready for review September 16, 2026 10:34
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adrianmoldovanwp, johnbillion.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

wporg-sync pushed a commit that referenced this pull request Sep 16, 2026
…ns controller tests.

These tests perform an HTTP request to the pattern directory on wordpress.org as a side effect of sending a request to the `wp/v2/block-patterns/patterns` REST API endpoint. The data from the remote pattern directory is not used in the test assertions. This change replaces those unnecessary HTTP requests with a mock response.

Developed in #13556

Props adrianmoldovanwp.

See #63914


git-svn-id: https://develop.svn.wordpress.org/trunk@63639 602fd350-edb4-49c9-b593-d223f7449a82
@johnbillion

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 16, 2026
…ns controller tests.

These tests perform an HTTP request to the pattern directory on wordpress.org as a side effect of sending a request to the `wp/v2/block-patterns/patterns` REST API endpoint. The data from the remote pattern directory is not used in the test assertions. This change replaces those unnecessary HTTP requests with a mock response.

Developed in WordPress/wordpress-develop#13556

Props adrianmoldovanwp.

See #63914

Built from https://develop.svn.wordpress.org/trunk@63639


git-svn-id: http://core.svn.wordpress.org/trunk@62814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants