1
0
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:
Márk Sági-Kazár 2019-04-15 07:52:55 +02:00 committed by GitHub
commit b44a8801fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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