GuzzleHttp\Handler\MockHandler::createWithMiddleware PHP Method

createWithMiddleware() public static method

Creates a new MockHandler that uses the default handler stack list of middlewares.
public static createWithMiddleware ( array $queue = null, callable $onFulfilled = null, callable $onRejected = null ) : GuzzleHttp\HandlerStack
$queue array Array of responses, callables, or exceptions.
$onFulfilled callable Callback to invoke when the return value is fulfilled.
$onRejected callable Callback to invoke when the return value is rejected.
return GuzzleHttp\HandlerStack
    public static function createWithMiddleware(array $queue = null, callable $onFulfilled = null, callable $onRejected = null)
    {
        return HandlerStack::create(new self($queue, $onFulfilled, $onRejected));
    }

Usage Example

 /**
  * @expectedException \GuzzleHttp\Exception\BadResponseException
  */
 public function testCanCreateWithDefaultMiddleware()
 {
     $r = new Response(500);
     $mock = MockHandler::createWithMiddleware([$r]);
     $request = new Request('GET', 'http://example.com');
     $mock($request, ['http_errors' => true])->wait();
 }