diff --git a/tests/phpunit/includes/mock-utils.php b/tests/phpunit/includes/mock-utils.php
new file mode 100644
index 0000000000..f47bbfb2b6
--- /dev/null
+++ b/tests/phpunit/includes/mock-utils.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Miscellaneous classes for mocking.
+ *
+ * @package WordPress
+ * @subpackage UnitTests
+ */
+
+/**
+ * Class used to mock a class that has __invoke method
+ */
+class Mock_REST_Invokable {
+
+	public function __invoke() {}
+}
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/tests/phpunit/tests/rest-api/rest-request.php
+++ b/tests/phpunit/tests/rest-api/rest-request.php
@@ -16,6 +16,9 @@ class Tests_REST_Request extends WP_UnitTestCase {
 		parent::set_up();
 
 		$this->request = new WP_REST_Request();
+
+		// Require necessary files.
+		require_once DIR_TESTROOT . '/includes/mock-utils.php';
 	}
 
 	public function test_header() {
@@ -1014,7 +1017,7 @@ class Tests_REST_Request extends WP_UnitTestCase {
 		$request->set_query_params( array( 'test' => 'value' ) );
 
 		$error    = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) );
-		$callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
+		$callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) );
 		$callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error );
 		$request->set_attributes(
 			array(
@@ -1038,7 +1041,7 @@ class Tests_REST_Request extends WP_UnitTestCase {
 		$request->set_query_params( array( 'test' => 'value' ) );
 
 		$error    = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) );
-		$callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
+		$callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) );
 		$callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error );
 		$request->set_attributes(
 			array(
@@ -1056,7 +1059,7 @@ class Tests_REST_Request extends WP_UnitTestCase {
 		$request = new WP_REST_Request();
 		$request->set_query_params( array( 'test' => 'value' ) );
 
-		$callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
+		$callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) );
 		$callback->expects( self::never() )->method( '__invoke' );
 		$request->set_attributes(
 			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/tests/phpunit/tests/rest-api/rest-server.php
+++ b/tests/phpunit/tests/rest-api/rest-server.php
@@ -18,6 +18,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
 		add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
 		$GLOBALS['wp_rest_server'] = rest_get_server();
 		remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
+
+		// Require necessary files.
+		require_once DIR_TESTROOT . '/includes/mock-utils.php';
 	}
 
 	public function tear_down() {
@@ -1573,9 +1576,9 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
 	 * @ticket 50244
 	 */
 	public function test_callbacks_are_not_executed_if_request_validation_fails() {
-		$callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
+		$callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) );
 		$callback->expects( self::never() )->method( '__invoke' );
-		$permission_callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
+		$permission_callback = $this->createPartialMock( 'Mock_REST_Invokable', array( '__invoke' ) );
 		$permission_callback->expects( self::never() )->method( '__invoke' );
 
 		register_rest_route(
