MockClient
class MockClient
Properties
| protected Fixture|MockResponse|Fixture|MockResponse> | $sequenceResponses | Responses consumed in registration order. |
|
| protected Fixture|MockResponse|Fixture|MockResponse> | $connectorResponses | Responses keyed by connector class. |
|
| protected Fixture|MockResponse|Fixture|MockResponse> | $requestResponses | Responses keyed by request class. |
|
| protected Fixture|MockResponse|Fixture|MockResponse> | $urlResponses | Responses keyed by URL pattern. |
|
| protected Response> | $recordedResponses | Recorded Saloon responses. |
|
| protected bool | $preventStrayRequests | Whether unmatched requests are prevented. |
|
| protected null|list<string> | $allowedStrayRequestUrls | URL patterns allowed to continue without a fake. |
|
| protected bool | $withoutResponseCache | Whether requests using this mock client bypass the response cache. |
Methods
Create a mock client.
Add mock responses.
Add a mock response.
Determine if no mock responses remain.
Prevent unmatched requests from reaching the network.
Allow unmatched requests to continue through the normal send lifecycle.
Get recorded responses, optionally filtered by a callback.
Get the last recorded request.
Get the last recorded pending request.
Get the last recorded response.
Assert that a matching request was sent.
Assert that no matching request was sent.
Assert that requests were sent in order.
Assert that nothing was sent.
Assert the number of recorded requests.
Bypass the response cache for requests using this mock client.
Determine if requests using this mock client bypass the response cache.
Register or retrieve the manager-backed global mock client.
Get the manager-backed global mock client.
Destroy the manager-backed global mock client.
Determine if any recorded response matches the request condition.
Determine if the recorded response matches the request condition.
Determine if the request satisfies a closure parameter type.
Determine if the pending request's URL matches the pattern.
Determine if the pending request may continue without a fake.
Resolve a configured response value.
Resolve the Saloon manager.
Details
at line 85
__construct(array $mockData = [])
Create a mock client.
at line 95
void
addResponses(array $responses)
Add mock responses.
at line 107
void
addResponse(MockResponse|Fixture|callable $response, string|null $captureMethod = null)
Add a mock response.
at line 133
MockResponse|Fixture|null
match(PendingRequest $pendingRequest)
Resolve the next matching response.
at line 170
bool
isEmpty()
Determine if no mock responses remain.
at line 183
MockClient
preventStrayRequests(bool $prevent = true)
Prevent unmatched requests from reaching the network.
at line 197
MockClient
allowStrayRequests(array|null $only = null)
Allow unmatched requests to continue through the normal send lifecycle.
at line 208
void
recordResponse(Response $response)
Record a response.
at line 218
Collection
recorded(callable|null $callback = null)
Get recorded responses, optionally filtered by a callback.
at line 232
Request|null
lastRequest()
Get the last recorded request.
at line 240
PendingRequest|null
lastPendingRequest()
Get the last recorded pending request.
at line 248
Response|null
lastResponse()
Get the last recorded response.
at line 256
void
assertSent(string|callable $value)
Assert that a matching request was sent.
at line 264
void
assertNotSent(string|callable $value)
Assert that no matching request was sent.
at line 274
void
assertSentInOrder(array $callbacks)
Assert that requests were sent in order.
at line 289
void
assertNothingSent()
Assert that nothing was sent.
at line 299
void
assertSentCount(int $count, string|null $requestClass = null)
Assert the number of recorded requests.
at line 316
MockClient
withoutCache()
Bypass the response cache for requests using this mock client.
at line 326
bool
shouldBypassResponseCache()
Determine if requests using this mock client bypass the response cache.
at line 342
static MockClient
global(array $mockData = [])
Register or retrieve the manager-backed global mock client.
The client persists until the test application is destroyed or
destroyGlobal() is called.
at line 353
static MockClient|null
getGlobal()
Get the manager-backed global mock client.
at line 363
static void
destroyGlobal()
Destroy the manager-backed global mock client.
This removes the recorder for every subsequent Saloon request in the worker.
at line 372
protected bool
requestWasSent(string|callable $value)
Determine if any recorded response matches the request condition.
at line 386
protected bool
responseMatches(Response $response, string|callable $value)
Determine if the recorded response matches the request condition.
at line 409
protected bool
requestMatchesType(Request $request, ReflectionType|null $type)
Determine if the request satisfies a closure parameter type.
at line 443
protected bool
urlMatches(string $pattern, PendingRequest $pendingRequest)
Determine if the pending request's URL matches the pattern.
A pattern may omit the scheme and host, and matches the URL with or without its query string.
at line 454
protected bool
allowsStrayRequest(PendingRequest $pendingRequest)
Determine if the pending request may continue without a fake.
at line 475
protected MockResponse|Fixture
resolveValue(MockResponse|Fixture|callable $value, PendingRequest $pendingRequest)
Resolve a configured response value.
at line 483
static protected SaloonManager
manager()
Resolve the Saloon manager.