Opened 14 months ago
Closed 14 hours ago
#63914 closed task (blessed) (fixed)
Reassess the need for the external-http tests
| Reported by: | johnbillion | Owned by: | lancewillett |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Tests in the external-http group are flakey because they rely on actual network requests over HTTP. There's no mocking in place. Server errors (HTTP 5XX) and more recently an increase in the frequency of HTTP 429 responses from wordpress.org will cause the tests to fail.
Let's reassess the tests in this group and question exactly what it is that each test is asserting.
As an example, the Tests_HTTP_Functions::test_head_404() test performs a HEAD request to a non-existent URL and then verifies that the response is not a WP_Error and that the response code is 404.
What exactly is this verifying though?
- If it's verifying the correct population of the HTTP response code then that should be handled by test coverage on
WP_HTTP_Requests_Responseand a mocked up\WpOrg\Requests\Responseinstance. No need to perform a real HTTP request. - If it's verifying specifically that a 404 response doesn't result in a
WP_Errorinstance being returned bywp_remote_*()then can we do that without performing an actual HTTP request? It should be possible with a test-only transport class which returns a mocked raw HTTP response.
Of course we need to be careful not to remove or reduce coverage where it's needed, but I'm positive we can remove many of the actual HTTP requests from these tests (and move them out of the external-http group).
Change History (103)
This ticket was mentioned in PR #9722 on WordPress/wordpress-develop by @johnbillion.
14 months ago
#1
- Keywords has-patch has-unit-tests added
#3
@
2 months ago
- Milestone Awaiting Review → 7.2
- Owner set to
- Status new → accepted
Making this claimable, now that #63083 has a patch.
https://github.com/WordPress/wordpress-develop/pull/13407 adds the guard: a test that makes an external request without @group external-http fails, and the request never leaves the machine. It should land first, so new offenders cannot appear while this list shrinks. Its description counts 86 tests in the group.
Trunk today carries @group external-http in 13 files (annotation count in brackets; a class-level annotation covers every test in the class):
tests/oembed/WpEmbed.php(5)tests/media.php(3)tests/rest-api/wpRestBlockPatternsController.php(2)tests/pomo/pluralForms.php(2)tests/http/wpGetHttpHeaders.php(2)tests/rest-api/rest-site-health-controller.php(1)tests/readme.php(1)tests/multisite/updateBlogStatus.php(1)tests/http/streams.php(1)tests/http/functions.php(1)tests/http/curl.php(1)tests/functions/wpRemoteFopen.php(1)tests/admin/includesTheme.php(1)
To claim a file, comment here with its name. For each test, ask what it proves. If the answer is about parsing a response, populating WP_HTTP_Requests_Response, or the shape of an error, mock the request with pre_http_request or a test transport and move the test out of the group. If the answer is only that the network works, propose removing it here. https://github.com/WordPress/wordpress-develop/pull/9722 is prior art for the mocking shape. One file per PR against this ticket, and run the group before and after: npm run test:php -- --group external-http.
This ticket was mentioned in PR #13554 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#5
Four tests in Tests_oEmbed_WpEmbed fetch http://example.com/embed/foo through WP_oEmbed::discover() and assert that WP_Embed falls back to a plain link when the request finds no oEmbed provider. A pre_http_request filter now answers that request with a 404 and an empty body. discover() returns false, as it does against the live URL, and the tests leave the external-http group. Tests_oEmbed_Controller keeps the coverage of the link-tag scan in discover().
Two more tests leave the group without a mock. test_autoembed_should_return_modified_content matches a registered handler before oEmbed runs. test_shortcode_should_return_empty_string_for_missing_url returns before it has a URL.
The group goes from 86 tests to 80.
Testing Instructions
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 80 tests and no failures. - Run
npm run test:php -- --exclude-group external-http tests/phpunit/tests/oembed/WpEmbed.php. Expect 24 tests and no failures. - Confirm the mock blocks the request. Remove the
add_filter( 'pre_http_request', ... )line fromtest_run_shortcode_url_only, then runnpm run test:php -- --filter Tests_oEmbed_WpEmbed::test_run_shortcode_url_only. Expect one failure: "This test made an external HTTP request but is not in theexternal-httpgroup." Restore the line. - Check the coding standards:
composer lint tests/phpunit/tests/oembed/WpEmbed.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, and drafting this description.
This ticket was mentioned in PR #13555 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#6
Trac ticket: TBD
Three tests in Tests_Media reach the network through WP_oEmbed: two discovery requests to example.com pages and, in test_multiline_comment_with_embeds, two YouTube oEmbed provider requests for made-up video IDs. Each test asserts that WP_Embed falls back to the plain URL, or to the embed_maybe_make_link filter, when oEmbed finds nothing. A pre_http_request filter now answers every request with a 200 HTML page that has no oEmbed link tags. discover() finds no provider and _parse_json() rejects the body, so each test takes the same fallback path it took against the live sites. The three tests leave the external-http group, and media.php no longer carries the annotation.
The group goes from 85 tests to 82.
Testing Instructions
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 82 tests and no failures. - Run
npm run test:php -- --exclude-group external-http tests/phpunit/tests/media.php. Expect 364 tests and no failures. - Check the coding standards:
composer lint tests/phpunit/tests/media.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 ticket was mentioned in PR #13556 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#8
Trac ticket: TBD
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
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 84 tests and no failures. - Run
npm run test:php -- --exclude-group external-http tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php. Expect 12 tests and no failures. - 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 theapi.wordpress.orgURLs. Restore the lines. - 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.
@johnbillion commented on PR #13554:
8 weeks ago
#11
@johnbillion commented on PR #13555:
8 weeks ago
#13
@johnbillion commented on PR #13556:
8 weeks ago
#15
This ticket was mentioned in PR #13603 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#16
Two tests in Tests_HTTP_wpGetHttpHeaders call wp_get_http_headers() with not_an_url and does_not_matter. wp_safe_remote_head() rejects both in wp_http_validate_url(), so no request left the machine. But pre_http_request runs 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_Error that WP_Http::request() returns for an invalid URL, and the tests leave the external-http group. wp_get_http_headers() gets the same error as before and returns false. Tests_HTTP_HTTP keeps the coverage of wp_http_validate_url().
The group goes from 80 tests to 78.
Testing Instructions
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 78 tests and no failures. - Run
npm run test:php -- --exclude-group external-http tests/phpunit/tests/http/wpGetHttpHeaders.php. Expect 3 tests and no failures. - Confirm the tests need the mock. Change the last line of
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. - Check the coding standards:
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 ticket was mentioned in PR #13605 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#17
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
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 84 tests and no failures. - Run
npm run test:php -- --exclude-group external-http tests/phpunit/tests/admin/includesTheme.php. Expect 6 tests and no failures. - 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 ticket was mentioned in PR #13606 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#18
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
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 84 tests and no failures. - Run
npm run test:php -- --exclude-group external-http tests/phpunit/tests/admin/includesTheme.php. Expect 6 tests and no failures. - 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 ticket was mentioned in PR #13607 on WordPress/wordpress-develop by @adrianmoldovanwp.
8 weeks ago
#19
Trac ticket: core.trac.wordpress.org/ticket/63914
Mock the oEmbed discovery request in Tests_Multisite_UpdateBlogStatus::test_content_from_spam_blog_is_not_available() with pre_http_request and move the test out of the external-http group.
The test embeds a URL from a spam site. get_oembed_response_data_for_url() refuses the embed before any request. WP_oEmbed::discover() then requests the URL from example.org, which is not a WordPress site and has no oEmbed link. The mock also has no oEmbed link, so it loses no coverage.
Testing Instructions
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --group external-http. Expect 85 tests and no failures. - Run
npm run test:php -- -c tests/phpunit/multisite.xml --exclude-group external-http tests/phpunit/tests/multisite/updateBlogStatus.php. Expect 12 tests and no failures. - In
get_oembed_response_data_for_url()insrc/wp-includes/embed.php, replace the condition below the commentDo not allow embeds for deleted/archived/spam sites.withfalse. Run step 3 again. Expecttest_content_from_spam_blog_is_not_availableto fail. Revert the change. - Check the coding standards:
composer lint tests/phpunit/tests/multisite/updateBlogStatus.php.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5.1, Claude Opus 5
Used for: Verifying the mock against the live code path, running the test suites.
@lancewillett commented on PR #13603:
7 weeks ago
#24
@lancewillett commented on PR #13606:
7 weeks ago
#25
@lancewillett commented on PR #13607:
7 weeks ago
#28
@lancewillett commented on PR #13605:
7 weeks ago
#30
This ticket was mentioned in PR #13705 on WordPress/wordpress-develop by @adrianmoldovanwp.
7 weeks ago
#31
Trac ticket: core.trac.wordpress.org/ticket/63914
Mock the request in Tests_Functions_wpRemoteFopen::test_wp_remote_fopen() with pre_http_request and move the test class out of the external-http group.
The test downloaded a PNG from s.w.org and checked its length. Tests_HTTP_Functions::test_get_request() downloads the same file and checks the same length, and it stays in the external-http group. The live request in this test added no coverage.
The mock also checks the request arguments. The test now fails if wp_remote_fopen() stops using wp_safe_remote_get() or drops its 10-second timeout. The old test checked neither. To prove it, change wp_safe_remote_get() to wp_remote_get() in wp_remote_fopen(): the test fails with "The request should use wp_safe_remote_get()."
The group was on the class, so test_wp_remote_fopen_empty() and test_wp_remote_fopen_bad_url() did not run by default, though neither sends a request. All three tests now run by default.
Testing Instructions
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --filter Tests_Functions_wpRemoteFopen. Expect 3 tests, 5 assertions and no failures. - Check the coding standards:
composer lint tests/phpunit/tests/functions/wpRemoteFopen.php.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5, Claude Opus 5.5
Used for: Reviewing the change against the live code path, adding the request argument checks, and running the tests.
@adrianmoldovanwp commented on PR #13705:
7 weeks ago
#32
Removing the class-level
external-httpgroup also moves the empty-URL and bad-URL tests into the default suite.
So, both now fail.
Fixed. I branched out of a stale trunk and after syncing the PR it broke.
This ticket was mentioned in PR #13755 on WordPress/wordpress-develop by @adrianmoldovanwp.
7 weeks ago
#33
Trac ticket: core.trac.wordpress.org/ticket/63914
PluralFormsTest::test_regression() checks that Plural_Forms picks the same plural form as the old eval() method, for each number from 0 to 200. It got the plural expressions from the GlotPress locales file, which it downloaded and loaded on each run. That put it in the external-http group, so the default suite never ran it.
A data provider now lists the plural expressions, and the test leaves the group. It runs in every PHPUnit job, and the default suite no longer loads a PHP file from the network.
The file has 82 locales that do not use n != 1, but only 21 distinct expressions. Many locales share one: fr, tr, and pt-br all use n > 1. The provider lists each expression once, keyed by one locale that uses it. A locale that shares an expression adds no coverage, so the test loses none. The list matches the current GlotPress file exactly, with no expression missing and none extra.
test_locales_file_not_empty() stays in external-http. It still downloads the file.
The external-http group goes from 71 tests to 70.
Testing Instructions
- Start the environment:
npm run env:start && npm run env:install. - Run
npm run test:php -- --filter PluralFormsTest. Expect 33 tests and no failures. Ontrunkthe same command runs 12. - Run
npm run test:php -- --group external-http --filter PluralFormsTest. Expect 1 test and no failures. - Check the coding standards:
composer lint tests/phpunit/tests/pomo/pluralForms.php.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5, Claude Opus 5.5
Used for: Checking the provider against the live GlotPress file, reviewing the change, running the test suites, 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.
🤖 Generated with Claude Code
@lancewillett commented on PR #13755:
7 weeks ago
#34
I’m comfortable with this approach.
The test still runs the real Plural_Forms parser against real GlotPress expressions and compares its output with the independent legacy evaluator. No parser or result is mocked.
I tested locally to verify that all 21 distinct expression/plural-count pairs match the current GlotPress file. WordPress reads these expressions from translation headers.
Downloading GlotPress’s source file is test setup, not a production integration, right?
There is tradeoff, though: newly added upstream expressions will no longer enter coverage automatically. Existing coverage is preserved, but automatic discovery is lost. I’d accept that tradeoff. Recording the upstream commit used for the snapshot would be a useful optional improvement. If automatic discovery is important, a separate scheduled compatibility check could retain it.
Local validation: 33 tests and 41 assertions passed in randomized single-site and multisite runs on PHP 8.3. PHPCS passed, and CI had 72 passing checks with nothing pending.
---
<sub>AI use: <code>gpt-6</code></sub>
@lancewillett commented on PR #13755:
7 weeks ago
#35
Tagging @johnbillion for a 2nd opinion
@adrianmoldovanwp commented on PR #13755:
6 weeks ago
#36
Recording the upstream commit used for the snapshot would be a useful optional improvement.
Done in e9b98e2
@lancewillett commented on PR #13705:
6 weeks ago
#37
@adimoldovan To land this one let's address John's latest comment.
Checking a Content-Length header doesn’t verify the downloaded body. Please correct that description claim and settle the coverage discussion so we can commit this.
@lancewillett commented on PR #13755:
6 weeks ago
#39
PR #13755 landed with https://core.trac.wordpress.org/changeset/63977
#40
@
6 weeks ago
Status on trunk today ([64005]): five files still carry @group external-http, down from 13 on September 8. Thanks @adrianmoldovanwp for the eight changesets so far.
functions/wpRemoteFopen.php: in review, https://github.com/WordPress/wordpress-develop/pull/13705http/functions.php: open to claimhttp/curl.php: open to claimhttp/streams.php: open to claimreadme.php: open to claim
These four are different from the files done so far. The http/ classes test the transports themselves, and readme.php checks the readme's PHP and MySQL versions against php.net and endoflife.date. Some tests here may need to stay in the group.
The question from comment:3 still applies to each test. If it proves parsing, response population, or error shape: mock it and move it out. If it proves only that the network works, propose removing it. If it needs a live request to prove anything, it can stay.
@adrianmoldovanwp commented on PR #13705:
6 weeks ago
#41
Actually I've changed my mind.
The
Tests_HTTP_Functions::test_get_request()test doesn't really cover the same thing, it asserts that theContent-Lengthheader has a value of153204which is different from asserting that the return value ofwp_remote_fopen()has a length of153204.
@johnbillion, you are right: test_get_request() checks the Content-Length header, not the body. I removed that claim from the description.
- Is that a valuable aspect of the function to test?
No. The part that belongs to the function is that it returns the body, and the mock checks that.
@lancewillett commented on PR #13705:
6 weeks ago
#42
@johnbillion The description now correctly distinguishes header checks from downloaded-body coverage. The mocked test verifies the wrapper’s returned body, safe-request setting, and timeout. Are you comfortable landing this and considering any additional transport-level body coverage separately?
<sub>AI review · <code>gpt-6</code></sub>
This ticket was mentioned in PR #13951 on WordPress/wordpress-develop by @shailu25.
5 weeks ago
#43
Trac ticket: #63914
What
Mocks the live network requests in Tests_HTTP_Functions with pre_http_request and removes the class from the external-http group.
Why
Per #63914, each test should be judged by what it proves. These tests assert response codes, header population, cookie retrieval helpers, and error shape — not that the network works. Mocking them matches the ticket guidance and prior art from landed PRs on this ticket.
test_get_cookie_host_only() already needed no network.
How
In tests/phpunit/tests/http/functions.php:
- Add a
pre_http_requestmock inset_up() - Return fixed responses for the PNG, redirect, 404, and login URLs via a shared
build_mock_http_response()helper - Return a
WP_Errorwith codehttp_request_failedwhenredirectionis negative (redirect-limit case), and assert that code - Echo request cookies into the mocked login response for the cookie-arg tests
- Return a clear
WP_Errorfor unexpected URLs - Remove
@group external-httpfrom the class - Call
wp_remote_head()/wp_remote_get()directly (retry wrappers are unnecessary with mocks)
Testing instructions
- From the repo root, run:
npm run test:php -- --filter Tests_HTTP_Functions
- Confirm all tests pass and are not in the
external-httpgroup:
npm run test:php -- --group external-http --filter Tests_HTTP_Functions
Expect 0 tests.
- Confirm the mock blocks the network. Temporarily remove
add_filter( 'pre_http_request', ... )fromset_up(), then run step 1 again. Expect failures from the external-http guard. Restore the filter.
Use of AI Tools
- Cursor
@shailu25 commented on PR #13951:
5 weeks ago
#45
Thanks @lancewillett — updated to follow your guidance:
- test_head_request / test_get_request now use WP_HTTP_Requests_Response fixtures for wp_remote_retrieve_*() coverage.
- Cookie and redirect tests no longer short-circuit via pre_http_request. They use a test-only Requests transport (WP_Http_Unit_Test_Transport) so request-cookie normalization, redirect handling, and response conversion still run.
Could you take another look when you have a chance?
@lancewillett commented on PR #13951:
5 weeks ago
#46
@shail-mehta Thanks for the update. The cookie and redirect coverage concerns are resolved: both fault injections now fail as expected, and local tests and CI pass.
Please address the two Copilot threads before we wrap up this review:
- For the identical response-helper tests, consolidating or renaming them remains optional. Using the new fake transport for the original direct HEAD/GET checks would also preserve that coverage. Please choose the clearest approach and reply in the thread.
- Update the PR description and testing instructions to match the fake transport. Keep the revised implementation; do not return to the earlier
pre_http_requestmock. Removing only the transport hook could permit live requests because the external-request blocker has also been removed.
I’m leaving the existing changes-requested review in place while these threads are addressed.
<sub>AI review · <code>gpt-6</code></sub>
@shailu25 commented on PR #13951:
5 weeks ago
#47
Thanks!
Addressed both points
- Switched test_head_request / test_get_request to the fake transport for direct HEAD/GET coverage
- Updated the PR description and testing instructions to match the transport approach (guard check removes use_mock_transport(), not only the transport hook)
@lancewillett commented on PR #13951:
5 weeks ago
#48
Before we commit, I've asked for a 2nd reviewer from @johnbillion, @mindctrl, or @adimoldovan.
@lancewillett commented on PR #13705:
5 weeks ago
#50
PR #13705 landed in https://core.trac.wordpress.org/changeset/64083
@lancewillett commented on PR #13951:
5 weeks ago
#52
PR #13951 landed in https://core.trac.wordpress.org/changeset/64096
This ticket was mentioned in PR #14020 on WordPress/wordpress-develop by @huzaifaalmesbah.
5 weeks ago
#53
Description
In tests/phpunit/tests/image/functions.php, test_wp_crop_image_with_url() was annotated with @group external-http because it performed a live HTTP request to https://s.w.org/screenshots/3.9/dashboard.png via PHP's stream wrapper during image loading. Additionally, test_wp_crop_image_should_fail_with_wp_error_object_if_url_does_not_exist() made an unmocked live request to wordpress.org.
This PR replaces the live network requests by mocking the https stream wrapper with Core's WP_Test_Stream in-memory fixture stream, removing live network dependencies and removing @group external-http from test_wp_crop_image_with_url().
Testing Instructions
- Run single-site PHPUnit tests for the image cropping methods:
npm run test:php -- --filter test_wp_crop_image
- Verify that the tests run and pass without requiring
--group external-http:npm run test:php -- --filter test_wp_crop_image_with_url
- Run multisite tests:
npm run test:php -- --filter test_wp_crop_image -c tests/phpunit/multisite.xml
Use of AI Tools
AI assistance: Yes
Tool(s): Google Antigravity
Model(s): Gemini 3.8 Flash
Used for: Brainstorming stream wrapper mocking with WP_Test_Stream and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.
This ticket was mentioned in PR #14021 on WordPress/wordpress-develop by @shailu25.
5 weeks ago
#54
Trac ticket: #63914
What
Moves the remaining Tests_Functions_wpRemoteFopen tests out of the external-http group.
Why
test_wp_remote_fopen_empty() never reaches the HTTP API: wp_remote_fopen() returns false after parse_url() fails.
test_wp_remote_fopen_bad_url() does call wp_safe_remote_get(), but WP_Http rejects the schemeless URL (wp.com) before any transport runs. The test was only in external-http because the suite’s external-HTTP guard runs on pre_http_request before that validation. Removing the guard for this test keeps the real rejection path and avoids a live request.
test_wp_remote_fopen() was already mocked with pre_http_request.
How
- Drop
@group external-httpfrom the empty and bad-URL tests - In the bad-URL test, remove
block_external_http_requestso URL validation can run without the guard recording a blocked request - Leave the successful-request mock as-is
Testing instructions
npm run test:php -- --filter Tests_Functions_wpRemoteFopen- Expect 3 tests, all passing, with no live HTTP
npm run test:php -- --group external-http --filter Tests_Functions_wpRemoteFopen- Expect 0 tests
Use of AI Tools
- Cursor
@lancewillett commented on PR #14020:
5 weeks ago
#55
Four changes needed before commit:
- Missing-URL test hits a different error under Imagick.
WP_Test_Stream::stream_open()always returns true, so the unregistered URL reads as an empty string. GD returnserror_loading_image; Imagick returnsinvalid_image("Zero size image string passed"). Use aWP_Test_Streamsubclass whosestream_open()returns false when no data is registered, and assert theerror_loading_imagecode. - Success test skips the URL path under GD.
is_file()is true on the mocked URL and false on a real HTTPS URL, so thehttps?://allowance inWP_Image_Editor_GD::load()is never needed. Have the same subclass return false fromurl_stat(). - Remove the new
tear_down(). Once the mock is registered,httpsis instream_get_wrappers(), so the guard never restores a leaked wrapper. Thetry/finallyblocks already clean up. - Keep
@requires extension opensslon both tests. Without a built-inhttpswrapper,stream_wrapper_unregister()andstream_wrapper_restore()emit warnings, which fail the tests. They skipped before.
<sub>AI review · <code>claude-opus-5-5</code></sub>
@huzaifaalmesbah commented on PR #14020:
5 weeks ago
#56
Thanks @lancewillett for the thorough review and guidance!
Updated in 3b301a01d0:
- Deterministic missing URL error code: Added
WP_Test_Stream_Http_Mock extends WP_Test_Streamwhosestream_open()returnsfalsewhen no data is registered for the requested path, ensuring both GD and Imagick consistently returnerror_loading_image. - Accurate URL handling in GD: Overrode
url_stat()to returnfalse, matching real HTTP/HTTPS stream behavior sois_file()returns false and GD follows its URL path. - Removed
tear_down(): Let thetry/finallyblocks handle restoring the wrapper cleanly. - Restored
@requires extension openssl: Kept@requires extension opensslon both URL test methods so they skip cleanly in environments without OpenSSL without emitting warnings.
Verified locally with PHPCS and PHPUnit across both single-site and multisite suites.
This ticket was mentioned in PR #14057 on WordPress/wordpress-develop by @shailu25.
5 weeks ago
#57
Trac ticket: #63914
What
Moves the http_api_curl handle-by-reference assertion out of the live-network Tests_HTTP_curl class and onto a mocked/local unit test of WP_HTTP_Requests_Hooks.
Why
That test only needed to prove http_api_curl receives the cURL handle by reference (do_action_ref_array). A real download from s.w.org was unnecessary and kept it in external-http.
How
- Add
Tests_HTTP_wpHttpRequestsHooks::test_http_api_curl_handle_is_passed_by_reference() - Dispatch Requests'
curl.before_sendthroughWP_HTTP_Requests_Hookswith a localcurl_init()handle - Remove the live-network version from
tests/phpunit/tests/http/curl.php
Note: Tests_HTTP_curl remains in external-http because it still inherits the live redirection/stream suite from base.php.
Testing instructions
npm run test:php -- --filter Tests_HTTP_wpHttpRequestsHooks- Expect 1 test, passing, with no live HTTP
npm run test:php -- --filter Tests_HTTP_curl --exclude-group external-http- Expect 0 tests (class still in
external-http)
Use of AI Tools
- Cursor
This ticket was mentioned in PR #14072 on WordPress/wordpress-develop by @shailu25.
5 weeks ago
#58
Trac ticket: #63914
What
Moves test_file_stream(), test_file_stream_limited_size(), and test_request_limited_size() out of the live-network WP_HTTP_UnitTestCase suite and onto mocked Tests_HTTP_Functions coverage.
Why
Those three tests only needed to assert streaming-to-disk and limit_response_size behavior against a known payload size. Downloading s.w.org/screenshots/3.9/dashboard.png over the live network kept them in external-http and made curl/streams runs flaky.
How
- Extend
WP_Http_Unit_Test_Transportto return a fixed-size canned body and honor Requests'filename/max_bytesoptions - Reimplement the three tests in
Tests_HTTP_Functionswith the fake transport - Remove them from
tests/phpunit/tests/http/base.phpso curl/streams no longer make live requests for stream/size coverage
Note: redirect, cookie, SSL, and other intentional live checks in WP_HTTP_UnitTestCase remain in external-http.
Testing instructions
npm run test:php -- --filter Tests_HTTP_Functions- Expect all tests passing, including the three stream/size tests, with no live HTTP
npm run test:php -- --filter "test_file_stream|test_request_limited_size" --group external-http- Expect 0 tests (moved out of
external-http)
Use of AI Tools
- Cursor
@lancewillett commented on PR #14020:
4 weeks ago
#60
PR #14020 landed in https://core.trac.wordpress.org/changeset/64264
@lancewillett commented on PR #14057:
4 weeks ago
#62
PR #14057 landed in https://core.trac.wordpress.org/changeset/64265
@shailu25 commented on PR #14072:
4 weeks ago
#63
Addressed feedback in latest commits.
@lancewillett commented on PR #14072:
4 weeks ago
#64
Optional follow-up in a separate PR: distinguish unavailable prerequisites from unexpected fixture-server startup failures, reporting a useful failure diagnostic for the latter rather than silently skipping coverage. Also apply the fixture-availability guard to Tests_HTTP_curl::test_http_api_curl_stream_parameter_is_a_reference(), which now uses the local fixture URL too. Neither needs to hold up this patch; the real-transport checks passed locally without skips.
<sub>AI review · <code>gpt-6</code></sub>
@lancewillett commented on PR #14072:
4 weeks ago
#66
PR #14072 landed in https://core.trac.wordpress.org/changeset/64277
This ticket was mentioned in PR #14148 on WordPress/wordpress-develop by @shailu25.
4 weeks ago
#67
Trac ticket: #63914
Follow-up to: #14072
What
Improves local HTTP stream fixture startup handling in WP_HTTP_UnitTestCase.
Updated file: tests/phpunit/tests/http/base.php
Why
After #14072, fixture startup failures were treated like missing prerequisites and silently skipped. That can hide real environment/setup problems and drop stream/size coverage without a clear signal.
How
- Skip only when a prerequisite is unavailable (
proc_open()missing) - Record unexpected startup failures (directory/payload/port/
proc_open/readiness) andfail()with a diagnostic inrequire_file_stream_fixture() - Make
require_file_stream_fixture()protectedfor subclass use - No change needed for
Tests_HTTP_curl::test_http_api_curl_stream_parameter_is_a_reference(); that coverage no longer uses the fixture URL
Testing instructions
- Start the local WordPress develop environment.
- Run:
npm run test:php -- --filter "test_file_stream|test_request_limited_size" --group external-http - Expect the stream/size tests to pass when the fixture server starts normally
Use of AI Tools
- Cursor
@lancewillett commented on PR #14148:
4 weeks ago
#69
PR #14148 landed in https://core.trac.wordpress.org/changeset/64288
This ticket was mentioned in PR #14677 on WordPress/wordpress-develop by @devmuhib.
3 weeks ago
#70
Description
In WP_HTTP_UnitTestCase, test methods testing HTTP redirection and headers historically made live requests to http://api.wordpress.org/core/tests/1.0/redirection.php.
This PR leverages the local PHP built-in web server fixture introduced in WP_HTTP_UnitTestCase by copying DIR_TESTDATA . '/WPHTTP-testcase-redirection-script.php' into the temporary fixture directory as redirection.php.
When the local fixture server is available, $this->redirection_script is automatically set to the local fixture URL (http://127.0.0.1:$port/redirection.php). This eliminates dozens of live network roundtrips to api.wordpress.org, dramatically improves test speed, and avoids test failures caused by external network latency or timeouts.
This ticket was mentioned in PR #14683 on WordPress/wordpress-develop by @devmuhib.
3 weeks ago
#71
Description
In Tests_Readme, get_response_body() contacts external APIs (php.net, endoflife.date, and mariadb.org) to verify the minimum recommended versions in readme.html.
Previously, if a request failed due to a network timeout or connection failure, assertNotWPError() caused an immediate hard test failure. Furthermore, only HTTP 503 was handled for skipping; other server errors or rate limiting (e.g. 429, 500, 502, 504) resulted in hard test failures.
This PR updates Tests_Readme::get_response_body() to:
- Check
is_wp_error( $response )and callmarkTestSkipped()with the error message when connection or timeout issues occur. - Gracefully skip on HTTP 429, 500, 502, 503, or 504 server responses.
This prevents intermittent external network outages and rate limits from causing CI test failures on trunk.
This ticket was mentioned in PR #14686 on WordPress/wordpress-develop by @devmuhib.
3 weeks ago
#72
Description
In Tests_Readme, the entire class was previously annotated with @group external-http, excluding all tests in this file from default test runs (npm run test:php).
This PR:
- Moves the
@group external-httpannotation from the class level down to the individual methods that actually contact external services (test_readme_php_version,test_readme_mysql_version, andtest_readme_mariadb_version). - Adds a new unit test
test_readme_contains_recommended_versions()that runs in the default test suite to assert thatreadme.htmlexists and contains declared recommended versions for PHP, MySQL, and MariaDB.
This allows any formatting changes, missing requirements, or syntax issues in readme.html to be caught immediately during default CI test runs without requiring network access or external HTTP calls.
@devmuhib commented on PR #14677:
3 weeks ago
#73
Updated! Now only points the test fixture URL to the local file when copy() succeeds, safely falling back to api.wordpress.org otherwise. Thank you @huzaifaalmesbah for the review!
@lancewillett commented on PR #14683:
2 weeks ago
#74
@devmuhib009 Could you please pick this one back up when you have time?
@lancewillett commented on PR #14686:
2 weeks ago
#76
PR #14686 landed in https://core.trac.wordpress.org/changeset/64732
@lancewillett commented on PR #14677:
2 weeks ago
#78
PR #14677 landed in https://core.trac.wordpress.org/changeset/64733
This ticket was mentioned in PR #15114 on WordPress/wordpress-develop by @shailu25.
13 days ago
#79
Trac ticket: #63914
What
Moves the remaining Tests_Functions_wpRemoteFopen tests out of the external-http group.
Why
test_wp_remote_fopen_empty() never reaches the HTTP API (parse_url() fails first).
test_wp_remote_fopen_bad_url() was in external-http because the suite HTTP guard runs on pre_http_request before URL validation. Mocking that path proves the same behavior without live network access.
test_wp_remote_fopen() was already mocked.
How
- Remove
@group external-httpfrom the empty and bad-URL tests - Mock a
WP_Errorfor the schemeless URL viapre_http_request, and assertwp_safe_remote_get()args - Leave the success-path mock as-is
- Add
@ticket 63914
Testing instructions
- Start the local environment:
npm run env:start && npm run env:install - Run:
npm run test:php -- --filter Tests_Functions_wpRemoteFopen - Expect 3 tests, all passing, with no live HTTP
- Run:
npm run test:php -- --group external-http --filter Tests_Functions_wpRemoteFopen - Expect 0 tests
Use of AI Tools
- Tool: Cursor
- Scope: Identified remaining
external-httptags onwp_remote_fopen()tests and drafted the minimal mock-based cleanup for review.
This ticket was mentioned in PR #15119 on WordPress/wordpress-develop by @shailu25.
13 days ago
#80
Trac ticket: #63914
What
Follow-up to #14686 / r64732: removes the three redundant assertNotEmpty() checks in test_readme_contains_recommended_versions().
Why
As noted in review on #14686, after a successful preg_match() with a + capture group, the captured version cannot be empty, so the extra assertions are unnecessary.
How
- Remove the three
assertNotEmpty()calls for PHP, MySQL, and MariaDB - Drop the unused match variables from
preg_match()
Testing instructions
npm run test:php -- --filter test_readme_contains_recommended_versions- Expect the test to pass with fewer assertions (no empty-capture checks)
Use of AI Tools
- Cursor
@rejaulalomkhan commented on PR #15119:
13 days ago
#81
The changes look good to me. Since preg_match() already ensures that the + capture group matches at least one character, the assertNotEmpty() checks were indeed redundant. Dropping the unused match variables also keeps the test clean. LGTM! 👍
@lancewillett commented on PR #15119:
13 days ago
#83
PR #15119 landed in https://core.trac.wordpress.org/changeset/64992
@lancewillett commented on PR #15114:
13 days ago
#84
PR #15114 landed in https://core.trac.wordpress.org/changeset/64992
This ticket was mentioned in PR #15184 on WordPress/wordpress-develop by @shailu25.
12 days ago
#85
Trac ticket: #63914
What
Moves test_cookie_handling() and test_ip_url_with_host_header() in WP_HTTP_UnitTestCase off hardcoded api.wordpress.org URLs onto the local redirection fixture. Updates WPHTTP-testcase-redirection-script.php so cookie Domain/Path attributes work on the local fixture host while keeping the historical wordpress.org cookie attributes for the live fallback.
Why
Those two tests still forced live network requests even when the local fixture was available. Per #63914, cookie acceptance/rejection and IP+Host request handling can be proven locally without depending on api.wordpress.org.
How
- Point
test_cookie_handling()at$this->redirection_script . '?cookie-test=1' - Build the IP URL and
Hostheader intest_ip_url_with_host_header()from$this->redirection_script(use the host as-is when it is already an IP; otherwise resolve viagethostbyname()) - For non-wordpress.org hosts, set host-only cookies and a fixture-relative path in the redirection script so the same PASS/FAIL cookie checks still run
- Add
@ticket 63914to both tests
Testing instructions
- Start the local environment:
npm run env:start && npm run env:install - Run:
npm run test:php -- --filter "test_cookie_handling|test_ip_url_with_host_header" --group external-http - Expect 4 tests (curl + streams), all passing, using the local fixture when available
- Confirm the cookie test no longer hardcodes
api.wordpress.orgintests/phpunit/tests/http/base.php
Use of AI Tools
- Cursor
@lancewillett commented on PR #15184:
11 days ago
#87
PR #15184 landed in https://core.trac.wordpress.org/changeset/65084
@lancewillett commented on PR #14683:
11 days ago
#88
One additional compatibility point from Copilot: the supported PHPUnit 5.7 path uses legacy assertion exceptions; the namespaced AssertionFailedError is not an alias there. Please preserve the supported-version behavior while explicitly rejecting skips in cases that expect a failure. No broader network-message matrix is needed.
<sub>AI review · <code>gpt-6</code></sub>
@lancewillett commented on PR #14683:
9 days ago
#90
PR #14683 landed in https://core.trac.wordpress.org/changeset/65176
This ticket was mentioned in PR #15488 on WordPress/wordpress-develop by @shailu25.
5 days ago
#91
What
Moves Tests_HTTP_curl out of the external-http group by running real cURL coverage against the local HTTP fixture, mocking the CA-bundle SSL-arg check, and keeping only test_ssl() as intentional live TLS smoke coverage.
Why
curl.php stayed in external-http because of live wordpress.org / api.wordpress.org dependencies. Redirect, stream, cookie, and header checks already prove transport behavior against the local fixture and do not need the public network.
How
- Allow loopback hosts (
127.0.0.1,localhost,::1) in the external-HTTP guard so local fixture requests can run outsideexternal-http - Require the local redirection fixture and remove the live
api.wordpress.orgfallback - Mock
test_https_url_without_ssl_verification()to assertsslcertificates/sslverifyoffline - Keep
test_ssl()with method-level@group external-http - Remove class-level
@group external-httpfromtests/phpunit/tests/http/curl.php
Testing instructions
- Start the local environment:
npm run env:start && npm run env:install - Run:
npm run test:php -- --filter Tests_HTTP_curl --exclude-group external-http - Expect 26 tests, all passing, with no live HTTP
- Run:
npm run test:php -- --filter 'Tests_HTTP_curl::test_ssl' --group external-http - Expect the live SSL smoke test to still run in
external-http
Use of AI Tools
- Cursor
@shailu25 commented on PR #15488:
4 days ago
#92
Thanks @lancewillett - both changes are in:
- Fixture-only exemption in
WP_HTTP_UnitTestCase;abstract-testcase.phpunchanged. test_https_url_without_ssl_verification()now asserts Requests verify / verifyname and stops before connecting.
Also noted your point that the redirect guard is defensive - left it in place.
@shailu25 commented on PR #15488:
4 days ago
#93
Thanks @lancewillett - both changes are in:
- Fixture-only exemption in
WP_HTTP_UnitTestCase;abstract-testcase.phpunchanged. test_https_url_without_ssl_verification()now asserts Requests verify / verifyname and stops before connecting.
Also noted your point that the redirect guard is defensive - left it in place.
@shailu25 commented on PR #15488:
4 days ago
#94
Thanks @lancewillett - both changes are in:
- Fixture-only exemption in
WP_HTTP_UnitTestCase;abstract-testcase.phpunchanged. test_https_url_without_ssl_verification()now asserts Requests verify / verifyname and stops before connecting.
Also noted your point that the redirect guard is defensive - left it in place.
One follow-up from CI: the redirect callback needed add_action( ..., 10, 5 ) so same-fixture redirects don’t hit an ArgumentCountError. That’s fixed now.
@shailu25 commented on PR #15488:
4 days ago
#95
Thanks @lancewillett!
- Restored
$http_request_args/filter_http_request_args()andassertNotEmpty( …['sslcertificates'] )alongside the Requests option checks.
@lancewillett commented on PR #15488:
4 days ago
#97
PR #15488 landed in https://core.trac.wordpress.org/changeset/65320
This ticket was mentioned in PR #15786 on WordPress/wordpress-develop by @shailu25.
3 days ago
#98
Trac ticket: #63914
What
Moves the three Tests_Readme version checks out of the external-http group by mocking php.net, endoflife.date, and MariaDB API responses.
Why
These methods were the last remaining live network dependency in readme.php after the offline declaration check landed in r64732. Mocked fixtures keep the parsing and support-window assertions without flaky external hosts.
How
- Remove
@group external-httpfromtest_readme_php_version,test_readme_mysql_version, andtest_readme_mariadb_version - Add
mock_http_response_body()fixtures shaped like the real API responses, keyed off the versions declared inreadme.html - Keep the existing
parse_response_body()skip/fail coverage as-is
Testing instructions
- Start the local environment:
npm run env:start && npm run env:install - Run:
npm run test:php -- --filter Tests_Readme --exclude-group external-http - Expect the full
Tests_Readmesuite to pass with no live HTTP - Run:
npm run test:php -- --group external-http --filter Tests_Readme - Expect 0 tests
Use of AI Tools
- Cursor
This ticket was mentioned in PR #15787 on WordPress/wordpress-develop by @shailu25.
3 days ago
#99
Trac ticket: #63914
What
Moves Tests_HTTP_streams out of the external-http group. Shared coverage in WP_HTTP_UnitTestCase already runs against the local HTTP fixture (landed with the cURL work in r65320 / #15488). Only test_ssl() stays in external-http as intentional live TLS smoke.
Why
After #15488, streams.php was the remaining transport class still tagged @group external-http at class level. Redirect, stream, cookie, and header checks do not need the public network.
How
- Remove class-level
@group external-httpfromtests/phpunit/tests/http/streams.php - Add
@ticket 63914to matchcurl.php - Leave
test_ssl()on method-level@group external-httpinbase.php
Testing instructions
- Start the local environment:
npm run env:start && npm run env:install - Run:
npm run test:php -- --filter Tests_HTTP_streams --exclude-group external-http - Expect the streams suite to pass with no live HTTP (same offline failures as trunk if any DNS-related skips elsewhere)
- Run:
npm run test:php -- --filter 'Tests_HTTP_streams::test_ssl' --group external-http - Expect the live SSL smoke test to still run in
external-http
Use of AI Tools
- Cursor
@shailu25 commented on PR #15787:
3 days ago
#100
@lancewillett commented on PR #15787:
3 days ago
#102
PR #15787 landed in https://core.trac.wordpress.org/changeset/65333
#103
@
14 hours ago
- Resolution → fixed
- Status accepted → closed
Excellent work everyone. Closing for 7.2. There's only 4 tests left in the external-http group:
test_readme_php_version()fetches supported PHP versions from php.nettest_readme_mysql_version()fetches supported MySQL versions from endoflife.datetest_readme_mariadb_version()fetches supported MariaDB versions from mariadb.orgtest_ssl()intentionally tests an actual TLS connection
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
#42076 was marked as a duplicate.