Class Mock
Implements sending requests to an array of stubbed responses
This adapter is not intended for production use. Instead
it is the backend used by Client::addMockResponse()
Namespace: Cake\Http\Client\Adapter
Property Summary
-
$responses protected
array<int, array{request: \Psr\Http\Message\RequestInterface, response: \Cake\Http\Client\Response, options: array<string, mixed>}>List of mocked responses.
Method Summary
-
addResponse() public
Add a mocked response.
Options
matchAn additional closure to match requests with.
-
send() public
Find a response if one exists.
-
urlMatches() protected
Check if the request URI matches the mock URI.
Method Detail
addResponse() ¶ public
addResponse(Psr\Http\Message\RequestInterface $request, Cake\Http\Client\Response $response, array{match?: \Closure(Psr\Http\Message\RequestInterface, array<string, mixed>): bool} $options): void
Add a mocked response.
Options
matchAn additional closure to match requests with.
Parameters
-
Psr\Http\Message\RequestInterface$request A partial request to use for matching.
-
Cake\Http\Client\Response$response The response that matches the request.
-
array{match?: \Closure(Psr\Http\Message\RequestInterface, array<string, mixed>): bool}$options See above.
Returns
voidsend() ¶ public
send(Psr\Http\Message\RequestInterface $request, array<string, mixed> $options): non-empty-list<Cake\Http\Client\Response>
Find a response if one exists.
Parameters
-
Psr\Http\Message\RequestInterface$request The request to match
-
array<string, mixed>$options The options are passed to match callbacks.
Returns
non-empty-list<Cake\Http\Client\Response>The matched response.
Throws
Cake\Http\Client\Exception\MissingResponseExceptionWhen no mock response matches.
urlMatches() ¶ protected
urlMatches(string $requestUri, Psr\Http\Message\RequestInterface $mock): bool
Check if the request URI matches the mock URI.
Parameters
-
string$requestUri The request being sent.
-
Psr\Http\Message\RequestInterface$mock The request being mocked.
Returns
boolProperty Detail
$responses ¶ protected
List of mocked responses.
Type
array<int, array{request: \Psr\Http\Message\RequestInterface, response: \Cake\Http\Client\Response, options: array<string, mixed>}>