Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Test gzinflate error
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvargiu committed Jan 13, 2019
1 parent 8cb7375 commit 8d17521
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 8d17521

Please sign in to comment.