Skip to content

Commit

Permalink
Upgrade Guzzle dependency from 5.x to 6.x
Browse files Browse the repository at this point in the history
Guzzle 6.x drops support for $response->json() because this method doesn't exist in the PSR-7 ResponseInterface. To fix this, we have to call json_decode() on $response->getBody() instead.

This was the only change needed to support Guzzle 6.x.
  • Loading branch information
soren121 committed Oct 5, 2017
1 parent 6979461 commit f7a65a8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"minimum-stability": "stable",
"require": {
"guzzlehttp/guzzle": "~5.2"
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*"
Expand Down
9 changes: 6 additions & 3 deletions src/HumanApi/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function batch($endpoint, array $params = array())
)
);

return $this->buildCollection($response->json());
$responseJson = json_decode($response->getBody(), true);
return $this->buildCollection($responseJson);

}

Expand All @@ -108,7 +109,8 @@ public function getUsers()
)
);

return $this->buildCollection($response->json());
$responseJson = json_decode($response->getBody(), true);
return $this->buildCollection($responseJson);

}

Expand All @@ -131,7 +133,8 @@ public function getUserById($humanId)
)
);

return new Model($response->json(), $this);
$responseJson = json_decode($response->getBody(), true);
return new Model($responseJson, $this);

}

Expand Down
4 changes: 3 additions & 1 deletion src/HumanApi/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function finish()
"json" => $this->sessionTokenData,
)
);
return $response->json();

$responseJson = json_decode($response->getBody(), true);
return $responseJson;
}
}
6 changes: 3 additions & 3 deletions src/HumanApi/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ protected function fetchResults($url, array $params = array())
)
);

$json = $response->json();
$responseJson = json_decode($response->getBody(), true);
if (!$this->listReturnsArray) {
$json = array($json);
$responseJson = array($responseJson);
}

return $this->buildCollection($json);
return $this->buildCollection($responseJson);

}

Expand Down
8 changes: 4 additions & 4 deletions tests/HumanApi/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ protected function getMockApplication($methods = null)
*/
protected function getMockResponse($statusCode = 204)
{
$response = $this->getMockBuilder('GuzzleHttp\Message\ResponseInterface')
$response = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')
->disableOriginalConstructor()
->setMethods(array("json", "getStatusCode", "getReasonPhrase"))
->setMethods(array("getBody", "getStatusCode", "getReasonPhrase"))
->getMockForAbstractClass();
$response->expects($this->any())
->method("json")
->willReturn(array());
->method("getBody")
->willReturn(json_encode(array()));
$response->expects($this->any())
->method("getStatusCode")
->willReturn($statusCode);
Expand Down
8 changes: 4 additions & 4 deletions tests/HumanApi/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class AuthTest extends \PHPUnit_Framework_TestCase
*/
protected function getMockResponse($statusCode = 204)
{
$response = $this->getMockBuilder('GuzzleHttp\Message\ResponseInterface')
$response = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')
->disableOriginalConstructor()
->setMethods(array("json", "getStatusCode", "getReasonPhrase"))
->setMethods(array("getBody", "getStatusCode", "getReasonPhrase"))
->getMockForAbstractClass();
$response->expects($this->any())
->method("json")
->willReturn(array());
->method("getBody")
->willReturn(json_encode(array()));
$response->expects($this->any())
->method("getStatusCode")
->willReturn($statusCode);
Expand Down
8 changes: 4 additions & 4 deletions tests/HumanApi/EndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ public function testFetchResults()

$result = array("id" => 1, "exampleKey" => "Test");

$response = $this->getMockBuilder('GuzzleHttp\Message\ResponseInterface')
$response = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')
->disableOriginalConstructor()
->setMethods(array("json"))
->setMethods(array("getBody"))
->getMockForAbstractClass();

$response->expects($this->once())
->method("json")
->willReturn($result);
->method("getBody")
->willReturn(json_encode($result));

$this->setProtectedProperty($endpoint, "method", "get");
$this->setProtectedProperty($endpoint, "accessToken", $accessToken);
Expand Down

0 comments on commit f7a65a8

Please sign in to comment.