public function testEmitsResponseHeaders() { $response = (new Response())->withStatus(200)->withAddedHeader('Content-Type', 'text/plain'); $response->getBody()->write('Content!'); ob_start(); $this->emitter->emit($response); ob_end_clean(); $this->assertContains('HTTP/1.1 200 OK', HeaderStack::stack()); $this->assertContains('Content-Type: text/plain', HeaderStack::stack()); }
public function testEmitsHeadersWithMultipleValuesMultipleTimes() { $server = ['HTTP_HOST' => 'example.com', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/foo/bar']; $callback = function ($req, $res) { $res = $res->withAddedHeader('Content-Type', 'text/plain'); $res = $res->withAddedHeader('Set-Cookie', 'foo=bar; expires=Wed, 1 Oct 2014 10:30; path=/foo; domain=example.com'); $res = $res->withAddedHeader('Set-Cookie', 'bar=baz; expires=Wed, 8 Oct 2014 10:30; path=/foo/bar; domain=example.com'); return $res; }; $server = Server::createServer($callback, $server, [], [], [], []); $server->listen(); $this->assertContains('HTTP/1.1 200 OK', HeaderStack::stack()); $this->assertContains('Content-Type: text/plain', HeaderStack::stack()); $this->assertContains('Set-Cookie: foo=bar; expires=Wed, 1 Oct 2014 10:30; path=/foo; domain=example.com', HeaderStack::stack()); $this->assertContains('Set-Cookie: bar=baz; expires=Wed, 8 Oct 2014 10:30; path=/foo/bar; domain=example.com', HeaderStack::stack()); $stack = HeaderStack::stack(); return $stack; }
/** * Emit a header, without creating actual output artifacts * * @param string $value */ function header($value) { HeaderStack::push($value); }