Tests: Avoid an infinite loop in Spy_REST_Server if a non-existing method is called.

Follow-up to [34928].

Props xknown, joemcgill.
Fixes #59601.

git-svn-id: https://develop.svn.wordpress.org/trunk@57133 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2023-11-23 14:39:16 +00:00
parent 9099d9789b
commit 09a2050fca
2 changed files with 9 additions and 0 deletions

View File

@ -25,6 +25,10 @@ class Spy_REST_Server extends WP_REST_Server {
* @return mixed * @return mixed
*/ */
public function __call( $method, $args ) { 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 ); return call_user_func_array( array( $this, $method ), $args );
} }

View File

@ -31,6 +31,11 @@ class Tests_REST_API extends WP_UnitTestCase {
return 'Spy_REST_Server'; 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. * Checks that the main classes are loaded.
*/ */