Docs: Improve documentation for tests/phpunit/includes/spy-rest-server.php
.
Props andizer. Fixes #47567. git-svn-id: https://develop.svn.wordpress.org/trunk@47253 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
22ca3c51a6
commit
49d8c4eff3
@ -8,7 +8,7 @@ class Spy_REST_Server extends WP_REST_Server {
|
|||||||
public $override_by_default = false;
|
public $override_by_default = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the raw $endpoints data from the server
|
* Gets the raw $endpoints data from the server.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -17,28 +17,39 @@ class Spy_REST_Server extends WP_REST_Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow calling protected methods from tests
|
* Allow calling protected methods from tests.
|
||||||
*
|
*
|
||||||
* @param string $method Method to call
|
* @param string $method Method to call.
|
||||||
* @param array $args Arguments to pass to the method
|
* @param array $args Arguments to pass to the method.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __call( $method, $args ) {
|
public function __call( $method, $args ) {
|
||||||
return call_user_func_array( array( $this, $method ), $args );
|
return call_user_func_array( array( $this, $method ), $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a header to the list of sent headers.
|
||||||
|
*
|
||||||
|
* @param string $header Header name.
|
||||||
|
* @param string $value Header value.
|
||||||
|
*/
|
||||||
public function send_header( $header, $value ) {
|
public function send_header( $header, $value ) {
|
||||||
$this->sent_headers[ $header ] = $value;
|
$this->sent_headers[ $header ] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a header from the list of sent headers.
|
||||||
|
*
|
||||||
|
* @param string $header Header name.
|
||||||
|
*/
|
||||||
public function remove_header( $header ) {
|
public function remove_header( $header ) {
|
||||||
unset( $this->sent_headers[ $header ] );
|
unset( $this->sent_headers[ $header ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the dispatch method so we can get a handle on the request object.
|
* Overrides the dispatch method so we can get a handle on the request object.
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request $request
|
* @param WP_REST_Request $request Request to attempt dispatching.
|
||||||
* @return WP_REST_Response Response returned by the callback.
|
* @return WP_REST_Response Response returned by the callback.
|
||||||
*/
|
*/
|
||||||
public function dispatch( $request ) {
|
public function dispatch( $request ) {
|
||||||
@ -47,19 +58,26 @@ class Spy_REST_Server extends WP_REST_Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the register_route method so we can re-register routes internally if needed.
|
* Overrides the register_route method so we can re-register routes internally if needed.
|
||||||
*
|
*
|
||||||
* @param string $namespace Namespace.
|
* @param string $namespace Namespace.
|
||||||
* @param string $route The REST route.
|
* @param string $route The REST route.
|
||||||
* @param array $route_args Route arguments.
|
* @param array $route_args Route arguments.
|
||||||
* @param bool $override Optional. Whether the route should be overridden if it already exists.
|
* @param bool $override Optional. Whether the route should be overridden if it already exists.
|
||||||
* Default false. Also set $GLOBALS['wp_rest_server']->override_by_default = true
|
* Default false. Also set `$GLOBALS['wp_rest_server']->override_by_default = true`
|
||||||
* to set overrides when you don't have access to the caller context.
|
* to set overrides when you don't have access to the caller context.
|
||||||
*/
|
*/
|
||||||
public function register_route( $namespace, $route, $route_args, $override = false ) {
|
public function register_route( $namespace, $route, $route_args, $override = false ) {
|
||||||
parent::register_route( $namespace, $route, $route_args, $override || $this->override_by_default );
|
parent::register_route( $namespace, $route, $route_args, $override || $this->override_by_default );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serves the request and returns the result.
|
||||||
|
*
|
||||||
|
* @param string $path Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used.
|
||||||
|
* Default null.
|
||||||
|
* @return null|false Null if not served and a HEAD request, false otherwise.
|
||||||
|
*/
|
||||||
public function serve_request( $path = null ) {
|
public function serve_request( $path = null ) {
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
Loading…
Reference in New Issue
Block a user