mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-04 06:37:06 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user