diff --git a/tests/phpunit/tests/admin/includesFile.php b/tests/phpunit/tests/admin/includesFile.php index eb6cc7c826..421137bc14 100644 --- a/tests/phpunit/tests/admin/includesFile.php +++ b/tests/phpunit/tests/admin/includesFile.php @@ -291,6 +291,9 @@ class Tests_Admin_IncludesFile extends WP_UnitTestCase { * @covers ::download_url */ public function test_download_url_no_warning_for_url_without_path() { + // Hook a mocked HTTP request response. + add_filter( 'pre_http_request', array( $this, 'mock_http_request' ), 10, 3 ); + $result = download_url( 'https://example.com' ); $this->assertIsString( $result ); @@ -306,6 +309,9 @@ class Tests_Admin_IncludesFile extends WP_UnitTestCase { * @covers ::download_url */ public function test_download_url_no_warning_for_url_without_path_with_signature_verification() { + // Hook a mocked HTTP request response. + add_filter( 'pre_http_request', array( $this, 'mock_http_request' ), 10, 3 ); + add_filter( 'wp_signature_hosts', static function( $urls ) { @@ -326,4 +332,24 @@ class Tests_Admin_IncludesFile extends WP_UnitTestCase { $this->assertWPError( $error ); $this->assertSame( 'signature_verification_no_signature', $error->get_error_code() ); } + + /** + * Mock the HTTP request response. + * + * @param bool $false False. + * @param array $arguments Request arguments. + * @param string $url Request URL. + * @return array|bool + */ + public function mock_http_request( $false, $arguments, $url ) { + if ( 'https://example.com' === $url ) { + return array( + 'response' => array( + 'code' => 200, + ), + ); + } + + return $false; + } } diff --git a/tests/phpunit/tests/functions/doEnclose.php b/tests/phpunit/tests/functions/doEnclose.php index 5c8a42089f..a72b603061 100644 --- a/tests/phpunit/tests/functions/doEnclose.php +++ b/tests/phpunit/tests/functions/doEnclose.php @@ -25,7 +25,7 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { */ public function set_up() { parent::set_up(); - add_filter( 'pre_http_request', array( $this, 'fake_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', array( $this, 'mock_http_request' ), 10, 3 ); } /** @@ -250,17 +250,16 @@ class Tests_Functions_DoEnclose extends WP_UnitTestCase { } /** - * Fake the HTTP request response. + * Mock the HTTP request response. * * @since 5.3.0 * * @param bool $false False. * @param array $arguments Request arguments. * @param string $url Request URL. - * * @return array Header. */ - public function fake_http_request( $false, $arguments, $url ) { + public function mock_http_request( $false, $arguments, $url ) { // Video and audio headers. $fake_headers = array( diff --git a/tests/phpunit/tests/http/wpGetHttpHeaders.php b/tests/phpunit/tests/http/wpGetHttpHeaders.php index 4b7b867a49..b462d7d8da 100644 --- a/tests/phpunit/tests/http/wpGetHttpHeaders.php +++ b/tests/phpunit/tests/http/wpGetHttpHeaders.php @@ -12,8 +12,8 @@ class Tests_HTTP_wpGetHttpHeaders extends WP_UnitTestCase { public function set_up() { parent::set_up(); - // Hook a fake HTTP request response. - add_filter( 'pre_http_request', array( $this, 'fake_http_request' ), 10, 3 ); + // Hook a mocked HTTP request response. + add_filter( 'pre_http_request', array( $this, 'mock_http_request' ), 10, 3 ); } /** @@ -47,10 +47,9 @@ class Tests_HTTP_wpGetHttpHeaders extends WP_UnitTestCase { * @param bool $false False. * @param array $arguments Request arguments. * @param string $url Request URL. - * * @return array|bool */ - public function fake_http_request( $false, $arguments, $url ) { + public function mock_http_request( $false, $arguments, $url ) { if ( 'http://example.com' === $url ) { return array( 'headers' => true ); }