From b82d40ecb33419dde809ce607f4f5134308da835 Mon Sep 17 00:00:00 2001 From: Kristofer Karlsson Date: Wed, 11 Sep 2024 19:54:04 +0200 Subject: [PATCH] Cast body to a string to force rewind of stream --- src/Http/Client.php | 6 +++--- tests/Http/ClientTest.php | 2 +- tests/TestCase.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Http/Client.php b/src/Http/Client.php index 529c90c4..a1e0c2c7 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -177,16 +177,16 @@ private function parseResponse(ResponseInterface $response) } if (!$this->isJSONResponse($response->getHeader('content-type'))) { - throw new InvalidResponseBodyException($response, $response->getBody()->getContents()); + throw new InvalidResponseBodyException($response, (string) $response->getBody()); } if ($response->getStatusCode() >= 300) { - $body = $this->json->unserialize($response->getBody()->getContents()) ?? $response->getReasonPhrase(); + $body = $this->json->unserialize((string) $response->getBody()) ?? $response->getReasonPhrase(); throw new ApiException($response, $body); } - return $this->json->unserialize($response->getBody()->getContents()); + return $this->json->unserialize((string) $response->getBody()); } /** diff --git a/tests/Http/ClientTest.php b/tests/Http/ClientTest.php index 34c6f46b..0e53b220 100644 --- a/tests/Http/ClientTest.php +++ b/tests/Http/ClientTest.php @@ -322,7 +322,7 @@ private function createHttpClientMock(int $status = 200, string $content = '{', { $stream = $this->createMock(StreamInterface::class); $stream->expects(self::once()) - ->method('getContents') + ->method('__toString') ->willReturn($content); $response = $this->createMock(ResponseInterface::class); diff --git a/tests/TestCase.php b/tests/TestCase.php index 4124be99..40659830 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -153,7 +153,7 @@ protected function createHttpClientMock(int $status = 200, string $content = '{' { $stream = $this->createMock(StreamInterface::class); $stream->expects(self::once()) - ->method('getContents') + ->method('__toString') ->willReturn($content); $response = $this->createMock(ResponseInterface::class);