mirror of
https://github.com/guzzle/guzzle.git
synced 2025-03-14 19:29:49 +01:00
Merge pull request #2050 from aredridel/document-body-in-testing
Document use of a body with mock responses
This commit is contained in:
commit
b44a8801fc
@ -32,7 +32,7 @@ a response or exception by shifting return values off of a queue.
|
||||
|
||||
// Create a mock and queue two responses.
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['X-Foo' => 'Bar']),
|
||||
new Response(200, ['X-Foo' => 'Bar'], 'Hello, World'),
|
||||
new Response(202, ['Content-Length' => 0]),
|
||||
new RequestException('Error Communicating with Server', new Request('GET', 'test'))
|
||||
]);
|
||||
@ -41,8 +41,11 @@ a response or exception by shifting return values off of a queue.
|
||||
$client = new Client(['handler' => $handlerStack]);
|
||||
|
||||
// The first request is intercepted with the first response.
|
||||
echo $client->request('GET', '/')->getStatusCode();
|
||||
$response = $client->request('GET', '/');
|
||||
echo $response->getStatusCode();
|
||||
//> 200
|
||||
echo $response->getBody();
|
||||
//> Hello, World
|
||||
// The second request is intercepted with the second response.
|
||||
echo $client->request('GET', '/')->getStatusCode();
|
||||
//> 202
|
||||
|
Loading…
x
Reference in New Issue
Block a user