From 6308640cbae4d9c447904edf9d8ebb780b5504a2 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 24 Jan 2018 10:23:14 -0800 Subject: [PATCH] fix guzzle5 handler merge options (#186) --- src/HttpHandler/Guzzle5HttpHandler.php | 2 +- tests/HttpHandler/Guzzle5HttpHandlerTest.php | 39 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/HttpHandler/Guzzle5HttpHandler.php b/src/HttpHandler/Guzzle5HttpHandler.php index f3e03eb02..b43fc22f8 100644 --- a/src/HttpHandler/Guzzle5HttpHandler.php +++ b/src/HttpHandler/Guzzle5HttpHandler.php @@ -108,7 +108,7 @@ private function createGuzzle5Request(RequestInterface $request, array $options) return $this->client->createRequest( $request->getMethod(), $request->getUri(), - array_merge([ + array_merge_recursive([ 'headers' => $request->getHeaders(), 'body' => $request->getBody(), ], $options) diff --git a/tests/HttpHandler/Guzzle5HttpHandlerTest.php b/tests/HttpHandler/Guzzle5HttpHandlerTest.php index fa18a944d..9ed40dfb6 100644 --- a/tests/HttpHandler/Guzzle5HttpHandlerTest.php +++ b/tests/HttpHandler/Guzzle5HttpHandlerTest.php @@ -175,4 +175,43 @@ public function testPromiseHandlesException() $promise = $handler->async($this->mockPsr7Request); $promise->wait(); } + + public function testCreateGuzzle5Request() + { + $requestHeaders = [ + 'header1' => 'value1', + 'header2' => 'value2', + ]; + $this->mockPsr7Request + ->expects($this->once()) + ->method('getHeaders') + ->will($this->returnValue($requestHeaders)); + $mockBody = $this->getMock('Psr\Http\Message\StreamInterface'); + $this->mockPsr7Request + ->expects($this->once()) + ->method('getBody') + ->will($this->returnValue($mockBody)); + $this->mockClient + ->expects($this->once()) + ->method('createRequest') + ->with(null, null, [ + 'headers' => $requestHeaders + ['header3' => 'value3'], + 'body' => $mockBody, + ]) + ->will($this->returnValue( + $this->getMock('GuzzleHttp\Message\RequestInterface') + )); + $this->mockClient + ->expects($this->once()) + ->method('send') + ->will($this->returnValue( + $this->getMock('GuzzleHttp\Message\ResponseInterface') + )); + $handler = new Guzzle5HttpHandler($this->mockClient); + $handler($this->mockPsr7Request, [ + 'headers' => [ + 'header3' => 'value3' + ] + ]); + } }