Skip to content

Build/Test Tools: Mock the external HTTP request in the Site Health controller test. - #13606

Closed
adimoldovan wants to merge 2 commits into
WordPress:trunkfrom
adimoldovan:63914-rest-site-health
Closed

adimoldovan wants to merge 2 commits into
WordPress:trunkfrom
adimoldovan:63914-rest-site-health

Conversation

@adimoldovan

@adimoldovan adimoldovan commented Sep 18, 2026 •

Copy link
Copy Markdown

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

Mock the WordPress.org request in WP_Test_REST_Site_Health_Controller::test() with pre_http_request and move the test out of the external-http group.

The test could not fail from the network. get_test_dotorg_communication() sets 'test' => 'dotorg_communication' before it calls wp_remote_get(), and the assertion only reads that key. Reachable or not, the test passed. So sitting in external-http bought 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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --exclude-group external-http tests/phpunit/tests/rest-api/rest-site-health-controller.php. Expect 5 tests and no failures.
  3. Run npm run test:php -- --group external-http. Expect no failures, and no Site Health controller test in the run.
  4. Check the coding standards: 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.

…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.
@adimoldovan adimoldovan self-assigned this Sep 22, 2026
@adimoldovan
adimoldovan requested a review from a team September 22, 2026 17:00
@adimoldovan
adimoldovan marked this pull request as ready for review September 22, 2026 17:01
@github-actions

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.

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
@lancewillett

Copy link
Copy Markdown
Member

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