Skip to content

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

Draft
adimoldovan wants to merge 1 commit into
WordPress:trunkfrom
adimoldovan:63914-rest-site-health
Draft

adimoldovan wants to merge 1 commit into
WordPress:trunkfrom
adimoldovan:63914-rest-site-health

Conversation

@adimoldovan

Copy link
Copy Markdown

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

Mock the Themes API request in Tests_Admin_IncludesTheme::test_get_theme_featured_list_api() with pre_http_request and move the test out of the external-http group.

The test asserted only a non-empty multidimensional array. get_theme_feature_list() returns the hard-coded list when the request fails, so a rate-limited response passed too. The test now asserts the exact translated output, with one feature slug that core does not know, 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/admin/includesTheme.php. Expect 6 tests and no failures.
  4. Check the coding standards: composer lint tests/phpunit/tests/admin/includesTheme.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.

…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.
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.

1 participant