Build/Test Tools: Mock the rejected requests in the wp_get_http_headers() tests. - #13603
Draft
adimoldovan wants to merge 2 commits into
Draft
adimoldovan wants to merge 2 commits into
adimoldovan wants to merge 2 commits into
Conversation
…ers()` tests. Two tests call `wp_get_http_headers()` with a URL that `wp_http_validate_url()` rejects. No request left the machine. But `pre_http_request` runs before that check, and the mock in this class passed those URLs on, so the guard against ungrouped external requests fails both tests. The mock now returns the `WP_Error` that `WP_Http::request()` returns for an invalid URL. The tests leave the `external-http` group.
| } | ||
|
|
||
| return $response; | ||
| return new WP_Error( 'http_request_failed', 'A valid URL was not provided.' ); |
Member
There was a problem hiding this comment.
The mock's @return false|array|WP_Error and its $response parameter are now dead, it can never return false and never reads $response.
Does that make sense?
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: https://core.trac.wordpress.org/ticket/63914
Two tests in
Tests_HTTP_wpGetHttpHeaderscallwp_get_http_headers()withnot_an_urlanddoes_not_matter.wp_safe_remote_head()rejects both inwp_http_validate_url(), so no request left the machine. Butpre_http_requestruns before that check, and the mock in this class passed those URLs on. The guard from [63560] then fails both tests.The mock now returns the
WP_ErrorthatWP_Http::request()returns for an invalid URL, and the tests leave theexternal-httpgroup.wp_get_http_headers()gets the same error as before and returns false.Tests_HTTP_HTTPkeeps the coverage ofwp_http_validate_url().The group goes from 80 tests to 78.
Testing Instructions
npm run env:start && npm run env:install.npm run test:php -- --group external-http. Expect 78 tests and no failures.npm run test:php -- --exclude-group external-http tests/phpunit/tests/http/wpGetHttpHeaders.php. Expect 3 tests and no failures.mock_http_request()back toreturn $response;, then run step 3 again. Expect two failures: "This test made an external HTTP request but is not in theexternal-httpgroup.", fornot_an_urlanddoes_not_matter. Restore the line.composer lint tests/phpunit/tests/http/wpGetHttpHeaders.php.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5.1
Used for: Tracing the request path, proving the tests made no network call, 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.