1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-04-22 07:32:41 +02:00

Documented throwing an exception in MockHandler

While exceptions are briefly mentioned in the preceding documentation, it is not immediately clear that exceptions can be thrown in the MockHandler, since my eyes are immediately drawn to the example code rather than the textual pre-amble.

With this, it is immediately clear to anyone that the stack can consist of both Responses and Exceptions.
This commit is contained in:
Troy Pavlek 2015-10-20 09:45:55 -06:00
parent 90d7d39a97
commit 0134b2fc82

View File

@ -27,11 +27,14 @@ a response or exception by shifting return values off of a queue.
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\RequestException;
// Create a mock and queue two responses.
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar']),
new Response(202, ['Content-Length' => 0])
new Response(202, ['Content-Length' => 0]),
new RequestException("Error Communicating with Server", new Request('GET', 'test'))
]);
$handler = HandlerStack::create($mock);