From f7a65a8eaecee8d17bcfcdc25a7ffe512f6594e1 Mon Sep 17 00:00:00 2001 From: Nicholas Narsing Date: Thu, 5 Oct 2017 11:50:02 -0400 Subject: [PATCH] Upgrade Guzzle dependency from 5.x to 6.x 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. --- composer.json | 2 +- src/HumanApi/Application.php | 9 ++++++--- src/HumanApi/Auth.php | 4 +++- src/HumanApi/Endpoint.php | 6 +++--- tests/HumanApi/ApplicationTest.php | 8 ++++---- tests/HumanApi/AuthTest.php | 8 ++++---- tests/HumanApi/EndpointTest.php | 8 ++++---- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 1ecd938..df7ba9d 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "minimum-stability": "stable", "require": { - "guzzlehttp/guzzle": "~5.2" + "guzzlehttp/guzzle": "~6.0" }, "require-dev": { "phpunit/phpunit": "4.6.*" diff --git a/src/HumanApi/Application.php b/src/HumanApi/Application.php index a48f2fa..197aa16 100644 --- a/src/HumanApi/Application.php +++ b/src/HumanApi/Application.php @@ -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); } @@ -108,7 +109,8 @@ public function getUsers() ) ); - return $this->buildCollection($response->json()); + $responseJson = json_decode($response->getBody(), true); + return $this->buildCollection($responseJson); } @@ -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); } diff --git a/src/HumanApi/Auth.php b/src/HumanApi/Auth.php index cd167ad..a02ecbd 100644 --- a/src/HumanApi/Auth.php +++ b/src/HumanApi/Auth.php @@ -56,6 +56,8 @@ public function finish() "json" => $this->sessionTokenData, ) ); - return $response->json(); + + $responseJson = json_decode($response->getBody(), true); + return $responseJson; } } diff --git a/src/HumanApi/Endpoint.php b/src/HumanApi/Endpoint.php index b512f08..c882e41 100644 --- a/src/HumanApi/Endpoint.php +++ b/src/HumanApi/Endpoint.php @@ -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); } diff --git a/tests/HumanApi/ApplicationTest.php b/tests/HumanApi/ApplicationTest.php index 13dfe43..1241726 100644 --- a/tests/HumanApi/ApplicationTest.php +++ b/tests/HumanApi/ApplicationTest.php @@ -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); diff --git a/tests/HumanApi/AuthTest.php b/tests/HumanApi/AuthTest.php index 298f620..824368a 100644 --- a/tests/HumanApi/AuthTest.php +++ b/tests/HumanApi/AuthTest.php @@ -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); diff --git a/tests/HumanApi/EndpointTest.php b/tests/HumanApi/EndpointTest.php index 0502702..9c74b57 100644 --- a/tests/HumanApi/EndpointTest.php +++ b/tests/HumanApi/EndpointTest.php @@ -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);