14 use PHPUnit\Framework\TestCase;
22 $response =
new StreamedResponse(
function () { echo
'foo'; }, 404, array(
'Content-Type' =>
'text/plain'));
24 $this->assertEquals(404, $response->getStatusCode());
25 $this->assertEquals(
'text/plain', $response->headers->get(
'Content-Type'));
32 $request->server->set(
'SERVER_PROTOCOL',
'HTTP/1.1');
34 $response->prepare($request);
36 $this->assertEquals(
'1.1', $response->getProtocolVersion());
37 $this->assertNotEquals(
'chunked', $response->headers->get(
'Transfer-Encoding'),
'Apache assumes responses with a Transfer-Encoding header set to chunked to already be encoded.');
44 $request->server->set(
'SERVER_PROTOCOL',
'HTTP/1.0');
46 $response->prepare($request);
48 $this->assertEquals(
'1.0', $response->getProtocolVersion());
49 $this->assertNull($response->headers->get(
'Transfer-Encoding'));
54 $response =
new StreamedResponse(
function () { echo
'foo'; }, 200, array(
'Content-Length' =>
'123'));
57 $response->prepare($request);
59 $this->assertSame(
'123', $response->headers->get(
'Content-Length'));
64 $response =
new StreamedResponse(
function () { echo
'foo'; }, 200, array(
'Cache-Control' =>
'max-age=600, public'));
67 $response->prepare($request);
68 $this->assertEquals(
'max-age=600, public', $response->headers->get(
'Cache-Control'));
77 $response->sendContent();
78 $this->assertEquals(1, $called);
80 $response->sendContent();
81 $this->assertEquals(1, $called);
90 $response->sendContent();
99 $response->setContent(
'foo');
105 $this->assertFalse($response->getContent());
112 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\StreamedResponse', $response);
113 $this->assertEquals(204, $response->getStatusCode());