MockResponse
in package
implements
ResponseInterface, StreamableInterface
uses
CommonResponseTrait, TransportResponseTrait
A test-friendly response.
Tags
Table of Contents
Interfaces
- ResponseInterface
- A (lazily retrieved) HTTP response.
- StreamableInterface
Properties
- $body : string|iterable<string|int, mixed>|null
- $idSequence : int
- $mainMulti : ClientState
- $requestMethod : string
- $requestOptions : array<string|int, mixed>
- $requestUrl : string
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
- readResponse() : void
- Simulates reading the response.
- writeRequest() : void
- Simulates sending the request.
Properties
$body
private
string|iterable<string|int, mixed>|null
$body
$idSequence
private
static int
$idSequence
= 0
$mainMulti
private
static ClientState
$mainMulti
$requestMethod
private
string
$requestMethod
$requestOptions
private
array<string|int, mixed>
$requestOptions
= []
$requestUrl
private
string
$requestUrl
Methods
__construct()
public
__construct([string|iterable<string|int, string|Throwable> $body = '' ][, array<string|int, mixed> $info = [] ]) : mixed
Parameters
- $body : string|iterable<string|int, string|Throwable> = ''
-
The response body as a string or an iterable of strings, yielding an empty string simulates an idle timeout, throwing or yielding an exception yields an ErrorChunk
- $info : array<string|int, mixed> = []
Tags
__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
Return values
intreadResponse()
Simulates reading the response.
private
static readResponse(self $response, array<string|int, mixed> $options, ResponseInterface $mock, int &$offset) : void
Parameters
- $response : self
- $options : array<string|int, mixed>
- $mock : ResponseInterface
- $offset : int
writeRequest()
Simulates sending the request.
private
static writeRequest(self $response, array<string|int, mixed> $options, ResponseInterface $mock) : void
Parameters
- $response : self
- $options : array<string|int, mixed>
- $mock : ResponseInterface