Skip to content

Commit b82d40e

Browse files
committed
Cast body to a string to force rewind of stream
1 parent 110be45 commit b82d40e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Http/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ private function parseResponse(ResponseInterface $response)
177177
}
178178

179179
if (!$this->isJSONResponse($response->getHeader('content-type'))) {
180-
throw new InvalidResponseBodyException($response, $response->getBody()->getContents());
180+
throw new InvalidResponseBodyException($response, (string) $response->getBody());
181181
}
182182

183183
if ($response->getStatusCode() >= 300) {
184-
$body = $this->json->unserialize($response->getBody()->getContents()) ?? $response->getReasonPhrase();
184+
$body = $this->json->unserialize((string) $response->getBody()) ?? $response->getReasonPhrase();
185185

186186
throw new ApiException($response, $body);
187187
}
188188

189-
return $this->json->unserialize($response->getBody()->getContents());
189+
return $this->json->unserialize((string) $response->getBody());
190190
}
191191

192192
/**

tests/Http/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private function createHttpClientMock(int $status = 200, string $content = '{',
322322
{
323323
$stream = $this->createMock(StreamInterface::class);
324324
$stream->expects(self::once())
325-
->method('getContents')
325+
->method('__toString')
326326
->willReturn($content);
327327

328328
$response = $this->createMock(ResponseInterface::class);

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function createHttpClientMock(int $status = 200, string $content = '{'
153153
{
154154
$stream = $this->createMock(StreamInterface::class);
155155
$stream->expects(self::once())
156-
->method('getContents')
156+
->method('__toString')
157157
->willReturn($content);
158158

159159
$response = $this->createMock(ResponseInterface::class);

0 commit comments

Comments
 (0)