Skip to content

Commit

Permalink
client: fixes legacy guzzle request objects instantiation
Browse files Browse the repository at this point in the history
Theres a big difference between `5.*` and `6.*` guzzle majors. So, in the `PagarMe\Sdk\Client::buildRequest` method the sdk should instantiate the correct request object accordingly its contracts, in this case twice: `\GuzzleHttp\Message\Request` and `\GuzzleHttp\Psr7\Request`.

If the user define request options, in guzzle `5.*` this options should be within the request object. If the major is `6.*` the options should be informed on `\GuzzleHttp\Client::send()` method as a second argument.

This fixes the described behavior above informing the request options on the right places.
  • Loading branch information
leonampd committed May 29, 2018
1 parent a5720b5 commit 2a1d179
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ public function send(RequestInterface $apiRequest)
private function buildRequest($apiRequest)
{
if (class_exists('\\GuzzleHttp\\Message\\Request')) {
$options = array_merge(
$this->requestOptions,
['json' => $this->buildBody($apiRequest)]
);
return $this->client->createRequest(
$apiRequest->getMethod(),
$apiRequest->getPath(),
['json' => $this->buildBody($apiRequest)]
$options
);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public function mustSendRequestWithProperContent()
'json' => [
'content' => self::CONTENT,
'api_key' => self::API_KEY
]
],
'timeout' => null
]
)
->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
Expand Down

0 comments on commit 2a1d179

Please sign in to comment.