Build/Test Tools: Mock the external HTTP request in the Site Health controller test. - #13606
Closed
adimoldovan wants to merge 2 commits into
Closed
adimoldovan wants to merge 2 commits into
adimoldovan wants to merge 2 commits into
Conversation
…ontroller test. `WP_Test_REST_Site_Health_Controller::test()` asserts only the `test` key of the response. `WP_Site_Health::get_test_dotorg_communication()` sets that key before it calls `wp_remote_get()`, so the request never changed the result of the test. Mock the request with `pre_http_request` and move the test out of the `external-http` group.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: 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 22, 2026
Mock the WordPress.org response in the Site Health REST controller test. Remove its external-http annotation so the administrator route test runs in the default suite without a network request. Developed in: #13606 Props adrianmoldovanwp, johnbillion. See #63914. git-svn-id: https://develop.svn.wordpress.org/trunk@63877 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync
pushed a commit
to WordPress/WordPress
that referenced
this pull request
Sep 22, 2026
Mock the WordPress.org response in the Site Health REST controller test. Remove its external-http annotation so the administrator route test runs in the default suite without a network request. Developed in: WordPress/wordpress-develop#13606 Props adrianmoldovanwp, johnbillion. See #63914. Built from https://develop.svn.wordpress.org/trunk@63877 git-svn-id: http://core.svn.wordpress.org/trunk@63049 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trac ticket: core.trac.wordpress.org/ticket/63914
Mock the WordPress.org request in
WP_Test_REST_Site_Health_Controller::test()withpre_http_requestand move the test out of theexternal-httpgroup.The test could not fail from the network.
get_test_dotorg_communication()sets'test' => 'dotorg_communication'before it callswp_remote_get(), and the assertion only reads that key. Reachable or not, the test passed. So sitting inexternal-httpbought nothing while costing a real request with a 10-second timeout on the failure path.The mock loses no coverage. The test still checks that an administrator reaches the route and gets the expected payload, the positive case for the permission checks in the rest of the file. It now runs in the default suite instead of the optional one, and
WP_UnitTestCase_Base::block_external_http_request()fails it if anyone drops the mock.Testing Instructions
npm run env:start && npm run env:install.npm run test:php -- --exclude-group external-http tests/phpunit/tests/rest-api/rest-site-health-controller.php. Expect 5 tests and no failures.npm run test:php -- --group external-http. Expect no failures, and no Site Health controller test in the run.composer lint tests/phpunit/tests/rest-api/rest-site-health-controller.php.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Verifying the mock against the live code path, reviewing the change, and drafting this description.
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.