From 8d175213166adf70ae9b66905b351601a199f764 Mon Sep 17 00:00:00 2001 From: Thomas Vargiu Date: Sun, 13 Jan 2019 17:04:08 +0100 Subject: [PATCH] Test gzinflate error --- test/ResponseTest.php | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/ResponseTest.php b/test/ResponseTest.php index b6d4a6d092..ad65a69930 100644 --- a/test/ResponseTest.php +++ b/test/ResponseTest.php @@ -16,6 +16,23 @@ class ResponseTest extends TestCase { + private $originalErrorReporting; + + protected function setUp() + { + $this->originalErrorReporting = \error_reporting(); + + parent::setUp(); + } + + protected function tearDown() + { + \error_reporting($this->originalErrorReporting); + + parent::tearDown(); + } + + public function testResponseFactoryFromStringCreatesValidResponse() { $string = 'HTTP/1.0 200 OK' . "\r\n\r\n" . 'Foo Bar'; @@ -165,6 +182,35 @@ public function testDeflateResponse() $this->assertEquals('ad62c21c3aa77b6a6f39600f6dd553b8', md5($res->getContent())); } + public function testDeflateResponseWithDeflateError() + { + \error_reporting(E_ALL ^ \E_STRICT ^ \E_WARNING); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('An error occurred during inflation'); + + $responseTest = <<<'REQ' +HTTP/1.1 200 OK +Date: Sun, 25 Jun 2006 19:38:02 GMT +Server: Apache +X-powered-by: PHP/5.1.4-pl3-gentoo +Content-encoding: deflate +Vary: Accept-Encoding +Content-length: 300 +Connection: close +Content-type: text/html + +REQ; + + // uncompressed data is more than 32768 times the length of the compressed input data + $data = \str_repeat('1', 10000000); + + $responseTest .= "\n" . \gzdeflate($data); + + $res = Response::fromString($responseTest); + $res->getBody(); + } + public function testDeflateResponseWithEmptyBody() { $responseTest = <<<'REQ'