Make WordPress Core

Changeset 57133


Ignore:
Timestamp:
11/23/2023 02:39:16 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/spy-rest-server.php

    r55027 r57133  
    2626         */
    2727        public function __call( $method, $args ) {
     28                if ( ! method_exists( $this, $method ) ) {
     29                        throw new Error( sprintf( 'Call to undefined method %s::%s()', get_class( $this ), $method ) );
     30                }
     31
    2832                return call_user_func_array( array( $this, $method ), $args );
    2933        }
  • trunk/tests/phpunit/tests/rest-api.php

    r56566 r57133  
    3030        public function filter_wp_rest_server_class( $class_name ) {
    3131                return 'Spy_REST_Server';
     32        }
     33
     34        public function test_rest_get_server_fails_with_undefined_method() {
     35                $this->expectException( Error::class );
     36                rest_get_server()->does_not_exist();
    3237        }
    3338
Note: See TracChangeset for help on using the changeset viewer.