diff --git a/tests/phpunit/includes/mock-invokable.php b/tests/phpunit/includes/mock-invokable.php
new file mode 100644
index 0000000000..03db3e053a
-
|
+
|
|
| 1 | <?php |
| 2 | /** |
| 3 | * File for Mock_Invokable class. |
| 4 | * |
| 5 | * @package WordPress |
| 6 | * @subpackage UnitTests |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Class Mock_Invokable. |
| 11 | * |
| 12 | * This class is using to mock a class that has __invoke method. |
| 13 | */ |
| 14 | class Mock_Invokable { |
| 15 | |
| 16 | public function __invoke() {} |
| 17 | } |
diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
index 836cb6159d..509c754f65 100644
a
|
b
|
class Tests_REST_Request extends WP_UnitTestCase { |
18 | 18 | $this->request = new WP_REST_Request(); |
19 | 19 | } |
20 | 20 | |
| 21 | /** |
| 22 | * Called before setting up all tests. |
| 23 | */ |
| 24 | public static function set_up_before_class() { |
| 25 | parent::set_up_before_class(); |
| 26 | |
| 27 | // Require files that need to load once. |
| 28 | require_once DIR_TESTROOT . '/includes/mock-invokable.php'; |
| 29 | } |
| 30 | |
21 | 31 | public function test_header() { |
22 | 32 | $value = 'application/x-wp-example'; |
23 | 33 | |
… |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
1014 | 1024 | $request->set_query_params( array( 'test' => 'value' ) ); |
1015 | 1025 | |
1016 | 1026 | $error = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) ); |
1017 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1027 | $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) ); |
1018 | 1028 | $callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error ); |
1019 | 1029 | $request->set_attributes( |
1020 | 1030 | array( |
… |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
1038 | 1048 | $request->set_query_params( array( 'test' => 'value' ) ); |
1039 | 1049 | |
1040 | 1050 | $error = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) ); |
1041 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1051 | $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) ); |
1042 | 1052 | $callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error ); |
1043 | 1053 | $request->set_attributes( |
1044 | 1054 | array( |
… |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
1056 | 1066 | $request = new WP_REST_Request(); |
1057 | 1067 | $request->set_query_params( array( 'test' => 'value' ) ); |
1058 | 1068 | |
1059 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1069 | $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) ); |
1060 | 1070 | $callback->expects( self::never() )->method( '__invoke' ); |
1061 | 1071 | $request->set_attributes( |
1062 | 1072 | array( |
diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
index 30977958fa..990cf30e79 100644
a
|
b
|
class Tests_REST_Server extends WP_Test_REST_TestCase { |
28 | 28 | parent::tear_down(); |
29 | 29 | } |
30 | 30 | |
| 31 | /** |
| 32 | * Called before setting up all tests. |
| 33 | */ |
| 34 | public static function set_up_before_class() { |
| 35 | parent::set_up_before_class(); |
| 36 | |
| 37 | // Require files that need to load once. |
| 38 | require_once DIR_TESTROOT . '/includes/mock-invokable.php'; |
| 39 | } |
| 40 | |
31 | 41 | public function test_envelope() { |
32 | 42 | $data = array( |
33 | 43 | 'amount of arbitrary data' => 'alot', |
… |
… |
class Tests_REST_Server extends WP_Test_REST_TestCase { |
1573 | 1583 | * @ticket 50244 |
1574 | 1584 | */ |
1575 | 1585 | public function test_callbacks_are_not_executed_if_request_validation_fails() { |
1576 | | $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1586 | $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) ); |
1577 | 1587 | $callback->expects( self::never() )->method( '__invoke' ); |
1578 | | $permission_callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) ); |
| 1588 | $permission_callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) ); |
1579 | 1589 | $permission_callback->expects( self::never() )->method( '__invoke' ); |
1580 | 1590 | |
1581 | 1591 | register_rest_route( |