Tests: Bring some consistency to mocking HTTP requests in unit tests.

Includes:
* Renaming the `$preempt` parameter to `$response` in the `pre_http_request` filter to better match the context used in callbacks (returning the original value if the conditions are not met rather than preempting the request).
* Synchronizing parameter names and types in various `pre_http_request` callbacks in unit tests.

Follow-up to [34509], [37907], [40628], [40629], [45667], [46175], [48242], [48462], [49904], [51021], [51973], [52146], [52382], [54043], [54968].

See #56793, #56792.

git-svn-id: https://develop.svn.wordpress.org/trunk@55029 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2023-01-05 10:21:19 +00:00
parent 53063c6333
commit d8f311800d
13 changed files with 60 additions and 60 deletions
@@ -522,10 +522,10 @@ class WP_REST_Pattern_Directory_Controller_Test extends WP_Test_REST_Controller_
private static function mock_successful_response( $action, $expects_results ) {
add_filter(
'pre_http_request',
static function ( $preempt, $args, $url ) use ( $action, $expects_results ) {
static function ( $response, $parsed_args, $url ) use ( $action, $expects_results ) {
if ( 'api.wordpress.org' !== wp_parse_url( $url, PHP_URL_HOST ) ) {
return $preempt;
return $response;
}
$response = array(
@@ -556,7 +556,7 @@ class WP_REST_Pattern_Directory_Controller_Test extends WP_Test_REST_Controller_
private static function prevent_requests_to_host( $blocked_host = 'api.wordpress.org' ) {
add_filter(
'pre_http_request',
static function ( $return, $args, $url ) use ( $blocked_host ) {
static function ( $response, $parsed_args, $url ) use ( $blocked_host ) {
if ( wp_parse_url( $url, PHP_URL_HOST ) === $blocked_host ) {
return new WP_Error(
@@ -567,7 +567,7 @@ class WP_REST_Pattern_Directory_Controller_Test extends WP_Test_REST_Controller_
}
return $return;
return $response;
},
10,
3