Mock
extends AbstractHandler
in package
HTTP client mock handler class
Tags
Table of Contents
Properties
- $history : array<string|int, mixed>
- Every request actually dispatched through this handler, in order
- $httpVersion : string
- HTTP version
- $matchers : array<string|int, mixed>
- Registered request matchers, checked in registration order before falling back to the queue
- $queue : array<string|int, mixed>
- Queued responses/throwables, FIFO
- $request : Request|null
- The request currently being (or last) prepared, carried so a thrown Client\Handler\Exception can implement NetworkExceptionInterface::getRequest()
- $resource : mixed
- Client resource object
- $uri : string|null
- URI string
Methods
- allowSelfSigned() : Mock
- Allow self-signed certs - no-op stub for interface parity with Curl/Stream
- disconnect() : void
- Close the handler connection
- getHttpVersion() : string
- Get the URI string
- getLastRequest() : Request|null
- Get the most recently dispatched request, if any
- getRequests() : array<string|int, mixed>
- Get every request actually dispatched through this handler, in order
- getResource() : mixed
- Get the resource
- getUri() : string|null
- Get the URI string
- getUriObject() : Uri
- Get the URI as an object
- hasResource() : bool
- Determine whether or not resource is available
- hasUri() : bool
- Determine whether or not there is a URI string
- prepare() : Mock
- Method to prepare the handler
- queue() : Mock
- Queue a response or throwable to be returned/thrown by the next send() that doesn't match a registered matcher
- reset() : Mock
- Method to reset the handler
- resource() : mixed
- Get the resource (alias method)
- send() : Response
- Method to send the request
- setVerifyPeer() : Mock
- Set verify peer - no-op stub for interface parity with Curl/Stream
- when() : Mock
- Register a response or throwable to return/throw for any request the given matcher accepts. Checked before the FIFO queue, in registration order - first match wins.
- collectRequestHeaders() : array<string|int, mixed>
- Collect the flat list of header strings for a request, shared by every handler
- resolveRequestBody() : array<string|int, mixed>
- Resolve what a request's outbound body should be, shared by every handler.
- resolveResult() : Response|Throwable
- Resolve the matched/queued result for the current request - registered matchers first (registration order, first match wins), then the FIFO queue, then throw if nothing resolves
Properties
$history
Every request actually dispatched through this handler, in order
protected
array<string|int, mixed>
$history
= []
$httpVersion
HTTP version
protected
string
$httpVersion
= '1.1'
$matchers
Registered request matchers, checked in registration order before falling back to the queue
protected
array<string|int, mixed>
$matchers
= []
$queue
Queued responses/throwables, FIFO
protected
array<string|int, mixed>
$queue
= []
$request
The request currently being (or last) prepared, carried so a thrown Client\Handler\Exception can implement NetworkExceptionInterface::getRequest()
protected
Request|null
$request
= null
$resource
Client resource object
protected
mixed
$resource
= null
$uri
URI string
protected
string|null
$uri
= null
Methods
allowSelfSigned()
Allow self-signed certs - no-op stub for interface parity with Curl/Stream
public
allowSelfSigned([bool $allow = true ]) : Mock
SSL settings are meaningless for a transport that sends no bytes. This exists so Client::prepare() can duck-type call it on any non-CurlMulti handler (including Mock) without a fatal 'call to undefined method' error.
Parameters
- $allow : bool = true
Return values
Mockdisconnect()
Close the handler connection
public
disconnect() : void
Full teardown, unlike reset() - clears the queue and history.
getHttpVersion()
Get the URI string
public
getHttpVersion() : string
Return values
stringgetLastRequest()
Get the most recently dispatched request, if any
public
getLastRequest() : Request|null
Return values
Request|nullgetRequests()
Get every request actually dispatched through this handler, in order
public
getRequests() : array<string|int, mixed>
Return values
array<string|int, mixed>getResource()
Get the resource
public
getResource() : mixed
getUri()
Get the URI string
public
getUri() : string|null
Return values
string|nullgetUriObject()
Get the URI as an object
public
getUriObject() : Uri
Return values
UrihasResource()
Determine whether or not resource is available
public
hasResource() : bool
Return values
boolhasUri()
Determine whether or not there is a URI string
public
hasUri() : bool
Return values
boolprepare()
Method to prepare the handler
public
prepare(Request $request[, Auth|null $auth = null ]) : Mock
Deliberately does not call collectRequestHeaders()/resolveRequestBody() - those build wire-format output for a real transport, and Mock never sends actual bytes. It does add the auth header and prepare request data, same as Curl/Stream, so a recorded request in history/matching is semantically complete.
Parameters
Return values
Mockqueue()
Queue a response or throwable to be returned/thrown by the next send() that doesn't match a registered matcher
public
queue(Response|Throwable $result) : Mock
Parameters
- $result : Response|Throwable
Return values
Mockreset()
Method to reset the handler
public
reset() : Mock
Deliberately does not clear the queue or history - those are the test's own configuration, not per-request wire-building state. Client::prepare() calls reset() on every reused handler between sequential send() calls on the same Client; clearing test-configured state here would silently break "queue N responses for N sequential calls", the most common use of this handler.
Return values
Mockresource()
Get the resource (alias method)
public
resource() : mixed
send()
Method to send the request
public
send() : Response
Tags
Return values
ResponsesetVerifyPeer()
Set verify peer - no-op stub for interface parity with Curl/Stream
public
setVerifyPeer([bool $verify = true ]) : Mock
SSL settings are meaningless for a transport that sends no bytes. This exists so Client::prepare() can duck-type call it on any non-CurlMulti handler (including Mock) without a fatal 'call to undefined method' error.
Parameters
- $verify : bool = true
Return values
Mockwhen()
Register a response or throwable to return/throw for any request the given matcher accepts. Checked before the FIFO queue, in registration order - first match wins.
public
when(callable $matcher, Response|Throwable $result) : Mock
Parameters
- $matcher : callable
-
callable(Request $request): bool
- $result : Response|Throwable
Return values
MockcollectRequestHeaders()
Collect the flat list of header strings for a request, shared by every handler
protected
collectRequestHeaders(Request $request) : array<string|int, mixed>
Parameters
- $request : Request
Return values
array<string|int, mixed>resolveRequestBody()
Resolve what a request's outbound body should be, shared by every handler.
protected
resolveRequestBody(Request $request) : array<string|int, mixed>
Multipart requests resolve to the curl-native array shape (scalars + CURLFile), which Curl can pass directly to CURLOPT_POSTFIELDS for zero-copy file streaming; handlers without that capability (Stream) fall back to Body\Multipart::build().
Parameters
- $request : Request
Return values
array<string|int, mixed>resolveResult()
Resolve the matched/queued result for the current request - registered matchers first (registration order, first match wins), then the FIFO queue, then throw if nothing resolves
protected
resolveResult() : Response|Throwable