Skip to content

Commit

Permalink
Tests: Avoid an infinite loop in Spy_REST_Server if a non-existing …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
SergeyBiryukov committed Nov 23, 2023
1 parent 9099d97 commit 09a2050
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/phpunit/includes/spy-rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function get_raw_endpoint_data() {
* @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 );
}

Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/tests/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function filter_wp_rest_server_class( $class_name ) {
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.
*/
Expand Down

0 comments on commit 09a2050

Please sign in to comment.