diff --git a/tests/phpunit/includes/spy-rest-server.php b/tests/phpunit/includes/spy-rest-server.php
index 49cda8748a..8bf1af43bd 100644
--- a/tests/phpunit/includes/spy-rest-server.php
+++ b/tests/phpunit/includes/spy-rest-server.php
@@ -25,6 +25,9 @@ class Spy_REST_Server extends WP_REST_Server {
 	 * @return mixed
 	 */
 	public function __call( $method, $args ) {
+		if ( ! method_exists( $this, $method ) ) {
+			throw new \Error( sprintf( 'Call to undefined method %s::%s', get_class( $this ), $method ) );
+		}
 		return call_user_func_array( array( $this, $method ), $args );
 	}
 
diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php
index 4a575b8803..2c9156cb30 100644
--- a/tests/phpunit/tests/rest-api.php
+++ b/tests/phpunit/tests/rest-api.php
@@ -2537,4 +2537,9 @@ class Tests_REST_API extends WP_UnitTestCase {
 
 		$this->assertTrue( $registered );
 	}
+
+	public function test_rest_get_server_fails_with_undefined_method() {
+		$this->expectException( \Error::class );
+		rest_get_server()->does_not_exist();
+	}
 }
