From bae45f7167a23f337f550a50dbf095d7d40dd629 Mon Sep 17 00:00:00 2001 From: Jay <602425+jshah4517@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:10:18 +0100 Subject: [PATCH] chore: bump psr/http-message requirement (#206) * chore: bump psr/http-message requirement * fix return types --- composer.json | 2 +- composer.lock | 18 +++++++++--------- test/Unit/ApiClientTest.php | 18 ++++++++++++++---- test/Unit/ApiTest.php | 15 +++++++++++++-- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 28245478..ab3f727d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "kevinrob/guzzle-cache-middleware": "^5.0", "phpdocumentor/reflection-docblock": "^5.2", "propaganistas/laravel-phone": "^5.3", - "psr/http-message": "^1.0", + "psr/http-message": "^1.1|^2.0", "supportpal/eloquent-model": "^1.0", "symfony/config": "^6.2|^7.0", "symfony/dependency-injection": "^6.2|^7.0", diff --git a/composer.lock b/composer.lock index d32dab8f..a0169c79 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8586f85d5e6a287eaf72b07f7ad80b12", + "content-hash": "0038c7a0ef95d09916902c94e918a1d1", "packages": [ { "name": "brick/math", @@ -2118,16 +2118,16 @@ }, { "name": "psr/http-message", - "version": "1.1", + "version": "2.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", - "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", - "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", "shasum": "" }, "require": { @@ -2136,7 +2136,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -2151,7 +2151,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", @@ -2165,9 +2165,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/1.1" + "source": "https://github.com/php-fig/http-message/tree/2.0" }, - "time": "2023-04-04T09:50:52+00:00" + "time": "2023-04-04T09:54:51+00:00" }, { "name": "psr/simple-cache", diff --git a/test/Unit/ApiClientTest.php b/test/Unit/ApiClientTest.php index 4e67f858..c4c92903 100644 --- a/test/Unit/ApiClientTest.php +++ b/test/Unit/ApiClientTest.php @@ -12,6 +12,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use SupportPal\ApiClient\Exception\HttpResponseException; use SupportPal\ApiClient\Http\Client; use SupportPal\ApiClient\Http\CoreClient; @@ -81,13 +82,17 @@ public function testResponseNonEncodeableException(): void $response = $this->prophesize(ResponseInterface::class); $response->getReasonPhrase()->shouldBeCalled()->willReturn(''); - $this - ->httpClient + $this->httpClient ->sendRequest($request->reveal()) ->willReturn($response->reveal()) ->shouldBeCalled(); - $response->getBody()->willReturn(''); + $streamProphecy = $this->prophesize(StreamInterface::class); + $streamProphecy->__toString() + ->willReturn('') + ->shouldBeCalled(); + + $response->getBody()->willReturn($streamProphecy->reveal()); /** @var RequestInterface $requestMock */ $requestMock = $request->reveal(); @@ -163,9 +168,14 @@ protected function sendRequestCommonExpectations( string $responseBody, ObjectProphecy $request ): ObjectProphecy { + $streamProphecy = $this->prophesize(StreamInterface::class); + $streamProphecy->__toString() + ->willReturn($responseBody) + ->shouldBeCalled(); + $response = $this->prophesize(ResponseInterface::class); $response->getStatusCode()->willReturn($statusCode); - $response->getBody()->willReturn($responseBody); + $response->getBody()->willReturn($streamProphecy->reveal()); $this->httpClient->sendRequest($request->reveal())->shouldBeCalled()->willReturn($response->reveal()); return $response; diff --git a/test/Unit/ApiTest.php b/test/Unit/ApiTest.php index a0a5f17e..f35e7b23 100644 --- a/test/Unit/ApiTest.php +++ b/test/Unit/ApiTest.php @@ -4,6 +4,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; use SupportPal\ApiClient\Api\Api; use SupportPal\ApiClient\Http\Client; use SupportPal\ApiClient\Model\Model; @@ -42,9 +43,14 @@ protected function setUp(): void */ protected function makeCommonExpectations(array $responseData, string $model): array { + $streamProphecy = $this->prophesize(StreamInterface::class); + $streamProphecy->__toString() + ->willReturn(json_encode($responseData)) + ->shouldBeCalled(); + $response = $this->prophesize(ResponseInterface::class); $response->getBody() - ->willReturn(json_encode($responseData)); + ->willReturn($streamProphecy->reveal()); if (is_array(current($responseData['data']))) { $models = []; @@ -68,9 +74,14 @@ protected function makeCommonExpectations(array $responseData, string $model): a */ protected function makeSuccessResponse() { + $streamProphecy = $this->prophesize(StreamInterface::class); + $streamProphecy->__toString() + ->willReturn(json_encode(['status' => 'success'])) + ->shouldBeCalled(); + $response = $this->prophesize(ResponseInterface::class); $response->getBody() - ->willReturn(json_encode(['status' => 'success'])); + ->willReturn($streamProphecy->reveal()); return $response; }