diff --git a/tests/phpunit/includes/spy-rest-server.php b/tests/phpunit/includes/spy-rest-server.php index 49cda8748a..4266a3de56 100644 --- a/tests/phpunit/includes/spy-rest-server.php +++ b/tests/phpunit/includes/spy-rest-server.php @@ -25,6 +25,10 @@ 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..7b0ee18f68 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -31,6 +31,11 @@ class Tests_REST_API extends WP_UnitTestCase { return 'Spy_REST_Server'; } + public function test_rest_get_server_fails_with_undefined_method() { + $this->expectException( Error::class ); + rest_get_server()->does_not_exist(); + } + /** * Checks that the main classes are loaded. */