Skip to content

Commit afaced5

Browse files
committed
Do not crash with binary response body
This is needed to simulate e.g. gzip response without having to override the `getRef` method.
1 parent 5cc49c1 commit afaced5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct( string $body, array $headers = [], int $status = 20
2424

2525
public function getRef() : string {
2626
$content = json_encode([
27-
$this->body,
27+
md5($this->body),
2828
$this->status,
2929
$this->headers,
3030
]);

test/Integration/MockWebServer_IntegrationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ public function testEmptySingle() : void {
251251
$this->assertSame('', file_get_contents($url));
252252
}
253253

254+
public function testBinaryResponse() : void {
255+
$response = new Response(
256+
gzencode('This is our http body response'),
257+
[ 'Content-Encoding: gzip' ],
258+
200
259+
);
260+
261+
$url = self::$server->setResponseOfPath('/', $response);
262+
$content = @file_get_contents($url);
263+
264+
$this->assertNotFalse($content);
265+
$this->assertSame('This is our http body response', gzdecode($content));
266+
$this->assertContains('Content-Encoding: gzip', $http_response_header);
267+
}
268+
254269
/**
255270
* @dataProvider requestInfoProvider
256271
*/

0 commit comments

Comments
 (0)