JsonMockResponse
extends MockResponse
in package
A test-friendly response.
Table of Contents
Methods
- __construct() : mixed
- __destruct() : mixed
- cancel() : void
- Closes the response stream and all related buffers.
- fromFile() : static
- getInfo() : mixed
- Returns info coming from the transport layer.
- getRequestMethod() : string
- Returns the method used when doing the request.
- getRequestOptions() : array<string|int, mixed>
- Returns the options used when doing the request.
- getRequestUrl() : string
- Returns the URL used when doing the request.
- close() : void
- perform() : void
- schedule() : void
- select() : int
Methods
__construct()
public
__construct([mixed $body = [] ][, array<string|int, mixed> $info = [] ]) : mixed
Parameters
- $body : mixed = []
-
Any value that
json_encode()can serialize - $info : array<string|int, mixed> = []
__destruct()
public
__destruct() : mixed
cancel()
Closes the response stream and all related buffers.
public
cancel() : void
No further chunk will be yielded after this method has been called.
fromFile()
public
static fromFile(string $path[, array<string|int, mixed> $info = [] ]) : static
Parameters
- $path : string
- $info : array<string|int, mixed> = []
Return values
staticgetInfo()
Returns info coming from the transport layer.
public
getInfo([string|null $type = null ]) : mixed
This method SHOULD NOT throw any ExceptionInterface and SHOULD be non-blocking. The returned info is "live": it can be empty and can change from one call to another, as the request/response progresses.
The following info MUST be returned:
- canceled (bool) - true if the response was canceled using ResponseInterface::cancel(), false otherwise
- error (string|null) - the error message when the transfer was aborted, null otherwise
- http_code (int) - the last response code or 0 when it is not known yet
- http_method (string) - the HTTP verb of the last request
- redirect_count (int) - the number of redirects followed while executing the request
- redirect_url (string|null) - the resolved location of redirect responses, null otherwise
- response_headers (array) - an array modelled after the special $http_response_header variable
- start_time (float) - the time when the request was sent or 0.0 when it's pending
- url (string) - the last effective URL of the request
- user_data (mixed) - the value of the "user_data" request option, null if not set
When the "capture_peer_cert_chain" option is true, the "peer_certificate_chain" attribute SHOULD list the peer certificates as an array of OpenSSL X.509 resources.
Other info SHOULD be named after curl_getinfo()'s associative return value.
Parameters
- $type : string|null = null
Return values
mixed —An array of all available info, or one of them when $type is provided, or null when an unsupported type is requested
getRequestMethod()
Returns the method used when doing the request.
public
getRequestMethod() : string
Return values
stringgetRequestOptions()
Returns the options used when doing the request.
public
getRequestOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getRequestUrl()
Returns the URL used when doing the request.
public
getRequestUrl() : string
Return values
stringclose()
protected
close() : void
perform()
protected
static perform(ClientState $multi, array<string|int, mixed> $responses) : void
Parameters
- $multi : ClientState
- $responses : array<string|int, mixed>
schedule()
protected
static schedule(self $response, array<string|int, mixed> &$runningResponses) : void
Parameters
- $response : self
- $runningResponses : array<string|int, mixed>
select()
protected
static select(ClientState $multi, float $timeout) : int
Parameters
- $multi : ClientState
- $timeout : float