diff --git a/tests/phpunit/includes/mock-utils.php b/tests/phpunit/includes/mock-utils.php
new file mode 100644
index 0000000000..f47bbfb2b6
-
|
+
|
|
| 1 | <?php |
| 2 | /** |
| 3 | * Miscellaneous classes for mocking. |
| 4 | * |
| 5 | * @package WordPress |
| 6 | * @subpackage UnitTests |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Class used to mock a class that has __invoke method |
| 11 | */ |
| 12 | class Mock_REST_Invokable { |
| 13 | |
| 14 | public function __invoke() {} |
| 15 | } |
diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
index 836cb6159d..9b0372ff9d 100644
a
|
b
|
class Tests_REST_Request extends WP_UnitTestCase { |
16 | 16 | parent::set_up(); |
17 | 17 | |
18 | 18 | $this->request = new WP_REST_Request(); |
| 19 | |
| 20 | // Require necessary files. |
| 21 | require_once DIR_TESTROOT . '/includes/mock-utils.php'; |
19 | 22 | } |
20 | 23 | |
21 | 24 | public function test_header() { |
… |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
1014 | 1017 | $request->set_query_params( array( 'test' => 'value' ) ); |
1015 | 1018 | |
1016 | 1019 | $error = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) ); |
1017 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1020 | $callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) ); |
1018 | 1021 | $callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error ); |
1019 | 1022 | $request->set_attributes( |
1020 | 1023 | array( |
… |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
1038 | 1041 | $request->set_query_params( array( 'test' => 'value' ) ); |
1039 | 1042 | |
1040 | 1043 | $error = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) ); |
1041 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1044 | $callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) ); |
1042 | 1045 | $callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error ); |
1043 | 1046 | $request->set_attributes( |
1044 | 1047 | array( |
… |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
1056 | 1059 | $request = new WP_REST_Request(); |
1057 | 1060 | $request->set_query_params( array( 'test' => 'value' ) ); |
1058 | 1061 | |
1059 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1062 | $callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) ); |
1060 | 1063 | $callback->expects( self::never() )->method( '__invoke' ); |
1061 | 1064 | $request->set_attributes( |
1062 | 1065 | array( |
diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
index 03d1cf21fa..af6a036aa9 100644
a
|
b
|
class Tests_REST_Server extends WP_Test_REST_TestCase { |
18 | 18 | add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); |
19 | 19 | $GLOBALS['wp_rest_server'] = rest_get_server(); |
20 | 20 | remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); |
| 21 | |
| 22 | // Require necessary files. |
| 23 | require_once DIR_TESTROOT . '/includes/mock-utils.php'; |
21 | 24 | } |
22 | 25 | |
23 | 26 | public function tear_down() { |
… |
… |
class Tests_REST_Server extends WP_Test_REST_TestCase { |
1573 | 1576 | * @ticket 50244 |
1574 | 1577 | */ |
1575 | 1578 | public function test_callbacks_are_not_executed_if_request_validation_fails() { |
1576 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1579 | $callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) ); |
1577 | 1580 | $callback->expects( self::never() )->method( '__invoke' ); |
1578 | | $permission_callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1581 | $permission_callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) ); |
1579 | 1582 | $permission_callback->expects( self::never() )->method( '__invoke' ); |
1580 | 1583 | |
1581 | 1584 | register_rest_route( |