Skip to content

Commit

Permalink
Merge pull request #2802 from mapogolions/fix/search-header-in-stack
Browse files Browse the repository at this point in the history
Incorrect search of a header in stack
  • Loading branch information
l0gicgate committed Aug 14, 2019
2 parents ed5ecf2 + 383627b commit a1ca5e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/Assets/HeaderStack.php
Expand Up @@ -79,11 +79,11 @@ public static function stack()
public static function has($header)
{
foreach (self::$data as $item) {
if ($item['header'] === $header) {
$components = explode(':', $item['header']);
if (trim($components[0]) === $header) {
return true;
}
}

return false;
}
}
30 changes: 27 additions & 3 deletions tests/ResponseEmitterTest.php
Expand Up @@ -40,16 +40,40 @@ public function testRespond()

public function testRespondNoContent()
{
$response = $this->createResponse();
$response = $this
->createResponse()
->withHeader('Content-Type', 'text/html')
->withHeader('Content-Length', '4096')
->withHeader('Cache-Control', 'no-cache');

$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);

$this->assertEquals(false, HeaderStack::has('Content-Type'));
$this->assertEquals(false, HeaderStack::has('Content-Length'));
$this->assertFalse(HeaderStack::has('Content-Type'));
$this->assertFalse(HeaderStack::has('Content-Length'));
$this->assertTrue(HeaderStack::has('Cache-Control'));
$this->expectOutputString('');
}

public function testNonEmptyResponse()
{
$response = $this
->createResponse()
->withHeader('Content-Type', 'text/html')
->withHeader('Content-Length', '4096')
->withHeader('Cache-Control', 'no-cache');

$response->getBody()->write('foo');

$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);

$this->assertTrue(HeaderStack::has('Content-Type'));
$this->assertTrue(HeaderStack::has('Content-Length'));
$this->assertTrue(HeaderStack::has('Cache-Control'));
$this->expectOutputString('foo');
}

public function testRespondWithPaddedStreamFilterOutput()
{
$availableFilter = stream_get_filters();
Expand Down

0 comments on commit a1ca5e9

Please sign in to comment.