From e96b074f7e54775fb45213733738cb20987510a4 Mon Sep 17 00:00:00 2001 From: Rei Bengu Date: Wed, 30 Jun 2021 12:54:28 +0200 Subject: [PATCH] Fix guzzle 6 compatibility issue --- src/Api/AppleApiClient.php | 1 - src/Api/Utils.php | 33 +++++++++++++++++++++++++++++++++ tests/Unit/Api/UtilsTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Api/Utils.php create mode 100644 tests/Unit/Api/UtilsTest.php diff --git a/src/Api/AppleApiClient.php b/src/Api/AppleApiClient.php index 537b2a5..4047b64 100644 --- a/src/Api/AppleApiClient.php +++ b/src/Api/AppleApiClient.php @@ -5,7 +5,6 @@ use Azimo\Apple\Api\Exception\PublicKeyFetchingFailedException; use Azimo\Apple\Api\Factory\ResponseFactory; use GuzzleHttp; -use GuzzleHttp\Utils; use InvalidArgumentException; final class AppleApiClient implements AppleApiClientInterface diff --git a/src/Api/Utils.php b/src/Api/Utils.php new file mode 100644 index 0000000..148fde2 --- /dev/null +++ b/src/Api/Utils.php @@ -0,0 +1,33 @@ +assertTrue(Utils::jsonDecode('true')); + $this->assertEquals(['a' => 1, 'b' => 2], Utils::jsonDecode('{"a":1,"b":2}', true)); + $this->assertEquals((object) ['a' => 1, 'b' => 2], Utils::jsonDecode('{"a":1,"b":2}')); + $this->assertEquals([5, 10], Utils::jsonDecode('[5, 10]', true)); + $this->assertEquals([5, 10], Utils::jsonDecode('[5, 10]')); + } + + public function testDecodesJsonAndThrowsOnError() + { + $this->expectException(InvalidArgumentException::class); + + Utils::jsonDecode('{{]]'); + } +}