From 125d78cc6ac74f8f272e23e59e1a0b75ecc8ad59 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com> Date: Fri, 18 Sep 2026 16:38:49 +0300 Subject: [PATCH] Build/Test Tools: Mock the external HTTP request in the Site Health controller test. `WP_Test_REST_Site_Health_Controller::test()` asserts only the `test` key of the response. `WP_Site_Health::get_test_dotorg_communication()` sets that key before it calls `wp_remote_get()`, so the request never changed the result of the test. Mock the request with `pre_http_request` and move the test out of the `external-http` group. --- .../rest-api/rest-site-health-controller.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-site-health-controller.php b/tests/phpunit/tests/rest-api/rest-site-health-controller.php index 9d67401d57d60..fce2704c09a59 100644 --- a/tests/phpunit/tests/rest-api/rest-site-health-controller.php +++ b/tests/phpunit/tests/rest-api/rest-site-health-controller.php @@ -92,11 +92,24 @@ static function () { $this->assertErrorResponse( 'rest_forbidden', $response, 403 ); } - /** - * @group external-http - */ public function test() { wp_set_current_user( self::$admin ); + add_filter( + 'pre_http_request', + static function () { + return array( + 'headers' => array(), + 'body' => '', + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), + 'cookies' => array(), + 'filename' => null, + ); + } + ); + $response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' ); $this->assertSame( 'dotorg_communication', $response->get_data()['test'] ); }