Make WordPress Core

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_Response and a mocked up \WpOrg\Requests\Response instance. No need to perform a real HTTP request.
  • If it's verifying specifically that a 404 response doesn't result in a WP_Error instance being returned by wp_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

#2 @johnbillion
11 months ago

#42076 was marked as a duplicate.

#3 @lancewillett
2 months ago

  • Milestone Awaiting Review → 7.2
  • Owner set to lancewillett
  • 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.

#4 @adrianmoldovanwp
8 weeks ago

I'm taking file tests/oembed/WpEmbed.php

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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --group external-http. Expect 80 tests and no failures.
  3. Run npm run test:php -- --exclude-group external-http tests/phpunit/tests/oembed/WpEmbed.php. Expect 24 tests and no failures.
  4. Confirm the mock blocks the request. Remove the add_filter( 'pre_http_request', ... ) line from test_run_shortcode_url_only, then run npm 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 the external-http group." Restore the line.
  5. 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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --group external-http. Expect 82 tests and no failures.
  3. Run npm run test:php -- --exclude-group external-http tests/phpunit/tests/media.php. Expect 364 tests and no failures.
  4. 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.

#7 @adrianmoldovanwp
8 weeks ago

Also taking tests/media.php

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

  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/rest-api/wpRestBlockPatternsController.php. Expect 12 tests and no failures.
  4. 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 the api.wordpress.org URLs. Restore the lines.
  5. 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.

#9 @adrianmoldovanwp
8 weeks ago

Taking tests/rest-api/wpRestBlockPatternsController.php

#10 @johnbillion
8 weeks ago

In 63635:

Build/Test Tools: Mock the external HTTP requests in the WP_Embed tests.

None of these tests need to, or should, perform a real HTTP request to example.com. This replaces those requests with a mock response.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13554

Props adrianmoldovanwp.

See #63914

#12 @johnbillion
8 weeks ago

In 63636:

Build/Test Tools: Mock the external HTTP requests in the media tests.

None of these tests need to, or should, perform a real HTTP request. This replaces those requests with a mock response.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13555

Props adrianmoldovanwp.

See #63914

#14 @johnbillion
8 weeks ago

In 63639:

Build/Test Tools: Mock the external HTTP requests in the block patterns controller tests.

These tests perform an HTTP request to the pattern directory on wordpress.org as a side effect of sending a request to the wp/v2/block-patterns/patterns REST API endpoint. The data from the remote pattern directory is not used in the test assertions. This change replaces those unnecessary HTTP requests with a mock response.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13556

Props adrianmoldovanwp.

See #63914

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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --group external-http. Expect 78 tests and no failures.
  3. Run npm run test:php -- --exclude-group external-http tests/phpunit/tests/http/wpGetHttpHeaders.php. Expect 3 tests and no failures.
  4. Confirm the tests need the mock. Change the last line of mock_http_request() back to return $response;, then run step 3 again. Expect two failures: "This test made an external HTTP request but is not in the external-http group.", for not_an_url and does_not_matter. Restore the line.
  5. 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

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

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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --group external-http. Expect 85 tests and no failures.
  3. 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.
  4. In get_oembed_response_data_for_url() in src/wp-includes/embed.php, replace the condition below the comment Do not allow embeds for deleted/archived/spam sites. with false. Run step 3 again. Expect test_content_from_spam_blog_is_not_available to fail. Revert the change.
  5. 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.

#20 @adrianmoldovanwp
7 weeks ago

Claimed tests/http/wpGetHttpHeaders.php

#21 @adrianmoldovanwp
7 weeks ago

Claimed tests/rest-api/rest-site-health-controller.php

#22 @lancewillett
7 weeks ago

In 63876:

Build/Test Tools: Mock rejected HTTP header requests.

Mock the error responses in the invalid-URL and deprecated-argument tests for wp_get_http_headers(). Remove their external-http annotations so both run in the default test suite, while unexpected requests remain subject to the HTTP guard.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13603

Props adrianmoldovanwp, mukesh27, johnbillion.
See #63914.

#23 @lancewillett
7 weeks ago

In 63877:

Build/Test Tools: Mock the Site Health controller HTTP request.

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: ​https://github.com/WordPress/wordpress-develop/pull/13606

Props adrianmoldovanwp, johnbillion.
See #63914.

#26 @adrianmoldovanwp
7 weeks ago

Claimed tests/multisite/updateBlogStatus.php

#27 @lancewillett
7 weeks ago

In 63879:

Build/Test Tools: Disable discovery in the spam site embed test.

Disable oEmbed discovery after marking the fixture site as spam, preventing the network fallback while preserving the local spam-site check. Remove the external-http annotation so the test runs in the default multisite suite.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13607

Props adrianmoldovanwp, johnbillion.
See #63914.

#29 @lancewillett
7 weeks ago

In 63900:

Build/Test Tools: Mock the theme feature list HTTP request.

Replace the live Themes API request with a mock response and move the test out of the external-http group. Assert the exact feature labels and the fallback for an unknown feature slug. Grant the test user Super Admin privileges on multisite so the API path is exercised there too.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13605

Props adrianmoldovanwp.
See #63914.

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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --filter Tests_Functions_wpRemoteFopen. Expect 3 tests, 5 assertions and no failures.
  3. 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-http group 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

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run npm run test:php -- --filter PluralFormsTest. Expect 33 tests and no failures. On trunk the same command runs 12.
  3. Run npm run test:php -- --group external-http --filter PluralFormsTest. Expect 1 test and no failures.
  4. 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.

#38 @lancewillett
6 weeks ago

In 63977:

Build/Test Tools: Remove the plural forms regression test's network dependency.

Use a data provider containing 21 distinct GlotPress plural expressions, with a pinned source reference, instead of downloading the locale file. Keep comparing the real parser with the legacy evaluator for values from 0 through 200, and run this coverage in the default test suite.

Remove the download-only locale availability test.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13755

Props adrianmoldovanwp, mukesh27, mindctrl.
See #63914.

#40 @lancewillett
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.

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 the Content-Length header has a value of 153204 which is different from asserting that the return value of wp_remote_fopen() has a length of 153204.

@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_request mock in set_up()
  • Return fixed responses for the PNG, redirect, 404, and login URLs via a shared build_mock_http_response() helper
  • Return a WP_Error with code http_request_failed when redirection is 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_Error for unexpected URLs
  • Remove @group external-http from the class
  • Call wp_remote_head() / wp_remote_get() directly (retry wrappers are unnecessary with mocks)

Testing instructions

  1. From the repo root, run:
npm run test:php -- --filter Tests_HTTP_Functions
  1. Confirm all tests pass and are not in the external-http group:
npm run test:php -- --group external-http --filter Tests_HTTP_Functions

Expect 0 tests.

  1. Confirm the mock blocks the network. Temporarily remove add_filter( 'pre_http_request', ... ) from set_up(), then run step 1 again. Expect failures from the external-http guard. Restore the filter.

Use of AI Tools

  • Cursor

#44 @shailu25
5 weeks ago

I'd like to claim tests/http/functions.php

​@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_request mock. 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.

#49 @lancewillett
5 weeks ago

In 64083:

Build/Test Tools: Mock the wp_remote_fopen() test request.

Replace the live image download with a mocked HTTP response. Verify that wp_remote_fopen() returns the response body, requests safe URL handling, and uses a 10-second timeout.

Move the success test into the default suite. Retain external-http on the empty-URL and bad-URL tests to preserve their real URL validation without triggering the default suite's HTTP guard.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13705

Props adrianmoldovanwp, johnbillion.
See #63914.

#51 @lancewillett
5 weeks ago

In 64096:

Tests: Remove live requests from HTTP function tests.

Use a test-only Requests transport to return canned HTTP responses while preserving real cookie normalization, redirect handling, and response conversion. Retain direct HEAD and GET coverage and move Tests_HTTP_Functions out of the external-http group.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13951

Props shailu25, adrianmoldovanwp.
See #63914.

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

  1. Run single-site PHPUnit tests for the image cropping methods:
    npm run test:php -- --filter test_wp_crop_image
    
  1. Verify that the tests run and pass without requiring --group external-http:
    npm run test:php -- --filter test_wp_crop_image_with_url
    
  1. 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-http from the empty and bad-URL tests
  • In the bad-URL test, remove block_external_http_request so URL validation can run without the guard recording a blocked request
  • Leave the successful-request mock as-is

Testing instructions

  1. npm run test:php -- --filter Tests_Functions_wpRemoteFopen
  2. Expect 3 tests, all passing, with no live HTTP
  3. npm run test:php -- --group external-http --filter Tests_Functions_wpRemoteFopen
  4. 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 returns error_loading_image; Imagick returns invalid_image ("Zero size image string passed"). Use a WP_Test_Stream subclass whose stream_open() returns false when no data is registered, and assert the error_loading_image code.
  • Success test skips the URL path under GD. is_file() is true on the mocked URL and false on a real HTTPS URL, so the https?:// allowance in WP_Image_Editor_GD::load() is never needed. Have the same subclass return false from url_stat().
  • Remove the new tear_down(). Once the mock is registered, https is in stream_get_wrappers(), so the guard never restores a leaked wrapper. The try/finally blocks already clean up.
  • Keep @requires extension openssl on both tests. Without a built-in https wrapper, stream_wrapper_unregister() and stream_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:

  1. Deterministic missing URL error code: Added WP_Test_Stream_Http_Mock extends WP_Test_Stream whose stream_open() returns false when no data is registered for the requested path, ensuring both GD and Imagick consistently return error_loading_image.
  2. Accurate URL handling in GD: Overrode url_stat() to return false, matching real HTTP/HTTPS stream behavior so is_file() returns false and GD follows its URL path.
  3. Removed tear_down(): Let the try/finally blocks handle restoring the wrapper cleanly.
  4. Restored @requires extension openssl: Kept @requires extension openssl on 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_send through WP_HTTP_Requests_Hooks with a local curl_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

  1. npm run test:php -- --filter Tests_HTTP_wpHttpRequestsHooks
  2. Expect 1 test, passing, with no live HTTP
  3. npm run test:php -- --filter Tests_HTTP_curl --exclude-group external-http
  4. 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_Transport to return a fixed-size canned body and honor Requests' filename / max_bytes options
  • Reimplement the three tests in Tests_HTTP_Functions with the fake transport
  • Remove them from tests/phpunit/tests/http/base.php so 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

  1. npm run test:php -- --filter Tests_HTTP_Functions
  2. Expect all tests passing, including the three stream/size tests, with no live HTTP
  3. npm run test:php -- --filter "test_file_stream|test_request_limited_size" --group external-http
  4. Expect 0 tests (moved out of external-http)

Use of AI Tools

  • Cursor

#59 @lancewillett
4 weeks ago

In 64264:

Tests: Mock remote image requests in cropping tests.

Use a fixture-backed HTTPS stream wrapper in the wp_crop_image() URL tests. Preserve real image cropping and missing-image error checks without relying on remote servers. Restore the wrapper after each request and retain the OpenSSL requirement.

Remove the successful URL test from the external-http group.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14020

Props huzaifaalmesbah.
See #63914.

#61 @lancewillett
4 weeks ago

In 64265:

Tests: Check cURL hook references without a live request.

Move the http_api_curl reference check into tests for WP_HTTP_Requests_Hooks. Dispatch curl.before_send with a local cURL handle and verify that changing the callback parameter changes the original handle variable.

Remove the live-request version from Tests_HTTP_curl, retaining its other external HTTP tests.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14057

Props shailu25.
See #63914.

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

#65 @lancewillett
4 weeks ago

In 64277:

Tests: Use a local fixture for HTTP streaming tests.

Preserve real transport coverage for streaming and response-size limits using a local HTTP fixture instead of a live download. Add mocked checks for forwarding the filename and max_bytes options to Requests.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14072

Props shailu25.
See #63914.

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) and fail() with a diagnostic in require_file_stream_fixture()
  • Make require_file_stream_fixture() protected for 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

  1. Start the local WordPress develop environment.
  2. Run: npm run test:php -- --filter "test_file_stream|test_request_limited_size" --group external-http
  3. Expect the stream/size tests to pass when the fixture server starts normally

Use of AI Tools

  • Cursor

#68 @lancewillett
4 weeks ago

In 64288:

Tests: Report HTTP fixture startup failures.

Distinguish missing prerequisites from unexpected local HTTP fixture startup failures. Skip when proc_open() is unavailable, and fail with a diagnostic when fixture setup or server startup fails.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14148

Props shailu25.
See #63914.

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:

  1. Check is_wp_error( $response ) and call markTestSkipped() with the error message when connection or timeout issues occur.
  2. 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:

  1. Moves the @group external-http annotation from the class level down to the individual methods that actually contact external services (test_readme_php_version, test_readme_mysql_version, and test_readme_mariadb_version).
  2. Adds a new unit test test_readme_contains_recommended_versions() that runs in the default test suite to assert that readme.html exists 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?

#75 @lancewillett
2 weeks ago

In 64732:

Tests: Check readme recommendations without external HTTP requests.

Run the offline check for recommended PHP, MySQL, and MariaDB version declarations in the default suite. Keep external-http on the three methods that check versions against external services.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14686

Props devmuhib, huzaifaalmesbah.
See #63914.

#77 @lancewillett
2 weeks ago

In 64733:

Tests: Serve HTTP redirection tests from the local fixture server.

Copy the redirection fixture into the existing local HTTP server directory and use its URL for redirect and header checks. Retain the external fallback when the local fixture is unavailable, and clear the fixture URL during teardown.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14677

Props devmuhib, huzaifaalmesbah.
See #63914.

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-http from the empty and bad-URL tests
  • Mock a WP_Error for the schemeless URL via pre_http_request, and assert wp_safe_remote_get() args
  • Leave the success-path mock as-is
  • Add @ticket 63914

Testing instructions

  1. Start the local environment: npm run env:start && npm run env:install
  2. Run: npm run test:php -- --filter Tests_Functions_wpRemoteFopen
  3. Expect 3 tests, all passing, with no live HTTP
  4. Run: npm run test:php -- --group external-http --filter Tests_Functions_wpRemoteFopen
  5. Expect 0 tests

Use of AI Tools

  • Tool: Cursor
  • Scope: Identified remaining external-http tags on wp_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

  1. npm run test:php -- --filter test_readme_contains_recommended_versions
  2. 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! 👍

#82 @lancewillett
13 days ago

In 64992:

Tests: Simplify offline readme and HTTP error checks.

Remove redundant assertNotEmpty() checks and unused match variables from the readme recommendation test. The existing preg_match() assertions require version text.

Mock HTTP errors for empty and schemeless URLs in the wp_remote_fopen() tests. Remove their external-http annotations so they run in the default suite, and verify the safe-request flag and timeout.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15119, ​https://github.com/WordPress/wordpress-develop/pull/15114

Props shailu25, rejaulalomkhan.
See #63914.

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 Host header in test_ip_url_with_host_header() from $this->redirection_script (use the host as-is when it is already an IP; otherwise resolve via gethostbyname())
  • 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 63914 to both tests

Testing instructions

  1. Start the local environment: npm run env:start && npm run env:install
  2. Run: npm run test:php -- --filter "test_cookie_handling|test_ip_url_with_host_header" --group external-http
  3. Expect 4 tests (curl + streams), all passing, using the local fixture when available
  4. Confirm the cookie test no longer hardcodes api.wordpress.org in tests/phpunit/tests/http/base.php

Use of AI Tools

  • Cursor

#86 @lancewillett
11 days ago

In 65084:

Tests: Use local fixtures for HTTP header and cookie checks.

Use the local redirection script for cookie handling and requests to an IP address with a custom Host header. Assert the header received by the server and retain the live endpoint fallback when the local fixture is unavailable.

Preserve parent-domain cookie acceptance coverage through a simulated transport while exercising real cookie parsing and redirect handling.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15184

Props shailu25.
See #63914.

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

#89 @lancewillett
9 days ago

In 65176:

Tests: Handle external version API availability failures.

Skip recognized availability failures in the readme version checks while retaining failures for invalid requests and unexpected responses. Add deterministic response checks that distinguish skipped tests from assertion failures.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14683

Props devmuhib, huzaifaalmesbah.
See #63914.

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 outside external-http
  • Require the local redirection fixture and remove the live api.wordpress.org fallback
  • Mock test_https_url_without_ssl_verification() to assert sslcertificates / sslverify offline
  • Keep test_ssl() with method-level @group external-http
  • Remove class-level @group external-http from tests/phpunit/tests/http/curl.php

Testing instructions

  1. Start the local environment: npm run env:start && npm run env:install
  2. Run: npm run test:php -- --filter Tests_HTTP_curl --exclude-group external-http
  3. Expect 26 tests, all passing, with no live HTTP
  4. Run: npm run test:php -- --filter 'Tests_HTTP_curl::test_ssl' --group external-http
  5. 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.php unchanged.
  • 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.php unchanged.
  • 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.php unchanged.
  • 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() and assertNotEmpty( …['sslcertificates'] ) alongside the Requests option checks.

#96 @lancewillett
4 days ago

In 65320:

Tests: Run the cURL transport tests without live external HTTP.

Follow-up to [34639], [64733], [65084].

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15488

Props shailu25.
See #63914.

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-http from test_readme_php_version, test_readme_mysql_version, and test_readme_mariadb_version
  • Add mock_http_response_body() fixtures shaped like the real API responses, keyed off the versions declared in readme.html
  • Keep the existing parse_response_body() skip/fail coverage as-is

Testing instructions

  1. Start the local environment: npm run env:start && npm run env:install
  2. Run: npm run test:php -- --filter Tests_Readme --exclude-group external-http
  3. Expect the full Tests_Readme suite to pass with no live HTTP
  4. Run: npm run test:php -- --group external-http --filter Tests_Readme
  5. 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-http from tests/phpunit/tests/http/streams.php
  • Add @ticket 63914 to match curl.php
  • Leave test_ssl() on method-level @group external-http in base.php

Testing instructions

  1. Start the local environment: npm run env:start && npm run env:install
  2. Run: npm run test:php -- --filter Tests_HTTP_streams --exclude-group external-http
  3. Expect the streams suite to pass with no live HTTP (same offline failures as trunk if any DNS-related skips elsewhere)
  4. Run: npm run test:php -- --filter 'Tests_HTTP_streams::test_ssl' --group external-http
  5. Expect the live SSL smoke test to still run in external-http

Use of AI Tools

  • Cursor

#101 @lancewillett
3 days ago

In 65333:

Tests: Run the streams transport tests without live external HTTP.

The HTTP transport tests chose a transport with the use_{$transport}_transport filters, which only WP_Http_Curl::test() and WP_Http_Streams::test() read. WP_Http::request() passes requests to Requests, which picked cURL, so Tests_HTTP_streams was running on cURL. Set the Requests transport for each test class instead, and move the streams tests out of the external-http group.

Follow-up to [65320].

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15787

Props shailu25.
See #63914.

#103 @johnbillion
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.net
  • test_readme_mysql_version() fetches supported MySQL versions from endoflife.date
  • test_readme_mariadb_version() fetches supported MariaDB versions from mariadb.org
  • test_ssl() intentionally tests an actual TLS connection
Note: See TracTickets for help on using tickets.