Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect search of a header in stack #2802

Merged
merged 2 commits into from Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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