MockClient
class MockClient
Traits
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. |
Methods
Get the class name of the first parameter of the given Closure.
Get the class names of the first parameter of the given Closure, including union types.
Get the class names / types of the parameters of the given Closure.
Get the class names / types of the return type of the given Closure.
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.
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 pending request may continue without a fake.
Resolve a configured response value.
Resolve the Saloon manager.
Details
in
ReflectsClosures at line 26
protected string
firstClosureParameterType(Closure $closure)
Get the class name of the first parameter of the given Closure.
in
ReflectsClosures at line 49
protected array
firstClosureParameterTypes(Closure $closure)
Get the class names of the first parameter of the given Closure, including union types.
in
ReflectsClosures at line 75
protected array
closureParameterTypes(Closure $closure)
Get the class names / types of the parameters of the given Closure.
in
ReflectsClosures at line 97
protected array
closureReturnTypes(Closure $closure)
Get the class names / types of the return type of the given Closure.
at line 78
__construct(array $mockData = [])
Create a mock client.
at line 88
void
addResponses(array $responses)
Add mock responses.
at line 100
void
addResponse(MockResponse|Fixture|callable $response, string|null $captureMethod = null)
Add a mock response.
at line 126
MockResponse|Fixture|null
match(PendingRequest $pendingRequest)
Resolve the next matching response.
at line 163
bool
isEmpty()
Determine if no mock responses remain.
at line 176
MockClient
preventStrayRequests(bool $prevent = true)
Prevent unmatched requests from reaching the network.
at line 190
MockClient
allowStrayRequests(array|null $only = null)
Allow unmatched requests to continue through the normal send lifecycle.
at line 201
void
recordResponse(Response $response)
Record a response.
at line 211
Collection
recorded(callable|null $callback = null)
Get recorded responses, optionally filtered by a callback.
at line 225
Request|null
lastRequest()
Get the last recorded request.
at line 233
PendingRequest|null
lastPendingRequest()
Get the last recorded pending request.
at line 241
Response|null
lastResponse()
Get the last recorded response.
at line 249
void
assertSent(string|callable $value)
Assert that a matching request was sent.
at line 257
void
assertNotSent(string|callable $value)
Assert that no matching request was sent.
at line 267
void
assertSentInOrder(array $callbacks)
Assert that requests were sent in order.
at line 282
void
assertNothingSent()
Assert that nothing was sent.
at line 292
void
assertSentCount(int $count, string|null $requestClass = null)
Assert the number of recorded requests.
at line 312
static MockClient
global(array $mockData = [])
Register or retrieve the manager-backed global mock client.
Tests only. The client persists until the test application is destroyed
or destroyGlobal() is called.
at line 322
static MockClient|null
getGlobal()
Get the manager-backed global mock client.
at line 330
static void
destroyGlobal()
Destroy the manager-backed global mock client.
at line 338
protected bool
requestWasSent(string|callable $value)
Determine if any recorded response matches the request condition.
at line 352
protected bool
responseMatches(Response $response, string|callable $value)
Determine if the recorded response matches the request condition.
at line 379
protected bool
allowsStrayRequest(PendingRequest $pendingRequest)
Determine if the pending request may continue without a fake.
at line 400
protected MockResponse|Fixture
resolveValue(MockResponse|Fixture|callable $value, PendingRequest $pendingRequest)
Resolve a configured response value.
at line 408
static protected SaloonManager
manager()
Resolve the Saloon manager.