SimpleMockedResponse
extends MockResponse
in package
A test-friendly response.
Tags
Table of Contents
Properties
- $body : mixed
- $content : string
- $headers : array<string, array<int, string>>
- $idSequence : mixed
- $mainMulti : mixed
- $requestMethod : mixed
- $requestOptions : mixed
- $requestUrl : mixed
- $statusCode : int
Methods
- __construct() : mixed
- cancel() : void
- Closes the response stream and all related buffers.
- getContent() : string
- Gets the response body as a string.
- getHeaders() : array<string|int, array<string|int, string>>
- Gets the HTTP headers of the response.
- 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.
- getStatusCode() : int
- Gets the HTTP status code of the response.
- toArray() : array<string, mixed>
- Gets the response body decoded as array, typically from a JSON payload.
- close() : void
- {@inheritdoc}
- perform() : void
- {@inheritdoc}
- schedule() : void
- {@inheritdoc}
- select() : int
- {@inheritdoc}
- getFlatHeaders() : array<int, string>
- readResponse() : mixed
- Simulates reading the response.
- writeRequest() : mixed
- Simulates sending the request.
Properties
$body
private
mixed
$body
$content
private
string
$content
= ''
$headers
private
array<string, array<int, string>>
$headers
= []
$idSequence
private
static mixed
$idSequence
= 0
$mainMulti
private
static mixed
$mainMulti
$requestMethod
private
mixed
$requestMethod
$requestOptions
private
mixed
$requestOptions
= []
$requestUrl
private
mixed
$requestUrl
$statusCode
private
int
$statusCode
Methods
__construct()
public
__construct([string $content = '' ][, array<string, string|array<int, string>> $headers = [] ][, int $statusCode = 200 ]) : mixed
Parameters
- $content : string = ''
- $headers : array<string, string|array<int, string>> = []
-
['name'=>'value'] OR ['name'=>['value']]
- $statusCode : int = 200
cancel()
Closes the response stream and all related buffers.
public
cancel() : void
getContent()
Gets the response body as a string.
public
getContent([bool $throw = true ]) : string
Parameters
- $throw : bool = true
-
Whether an exception should be thrown on 3/4/5xx status codes
Return values
stringgetHeaders()
Gets the HTTP headers of the response.
public
getHeaders([bool $throw = true ]) : array<string|int, array<string|int, string>>
Parameters
- $throw : bool = true
-
Whether an exception should be thrown on 3/4/5xx status codes
Return values
array<string|int, array<string|int, string>> —The headers of the response keyed by header names in lowercase
getInfo()
Returns info coming from the transport layer.
public
getInfo([string|null $type = null ]) : mixed
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
stringgetStatusCode()
Gets the HTTP status code of the response.
public
getStatusCode() : int
Return values
inttoArray()
Gets the response body decoded as array, typically from a JSON payload.
public
toArray([bool $throw = true ]) : array<string, mixed>
Parameters
- $throw : bool = true
-
Whether an exception should be thrown on 3/4/5xx status codes
Return values
array<string, mixed>close()
{@inheritdoc}
protected
close() : void
perform()
{@inheritdoc}
protected
static perform(ClientState $multi, array<string|int, mixed> &$responses) : void
Parameters
- $multi : ClientState
- $responses : array<string|int, mixed>
schedule()
{@inheritdoc}
protected
static schedule(self $response, array<string|int, mixed> &$runningResponses) : void
Parameters
- $response : self
- $runningResponses : array<string|int, mixed>
select()
{@inheritdoc}
protected
static select(ClientState $multi, float $timeout) : int
Parameters
- $multi : ClientState
- $timeout : float
Return values
intgetFlatHeaders()
private
getFlatHeaders() : array<int, string>
Return values
array<int, string>readResponse()
Simulates reading the response.
private
static readResponse(self $response, array<string|int, mixed> $options, ResponseInterface $mock, int &$offset) : mixed
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) : mixed
Parameters
- $response : self
- $options : array<string|int, mixed>
- $mock : ResponseInterface