streamed response should return $this

This commit is contained in:
DQNEO 2017-10-19 22:42:56 +09:00 committed by Nicolas Grekas
parent 2fc9b57f65
commit 058fb84554
2 changed files with 16 additions and 3 deletions

View File

@ -83,12 +83,12 @@ class StreamedResponse extends Response
public function sendHeaders() public function sendHeaders()
{ {
if ($this->headersSent) { if ($this->headersSent) {
return; return $this;
} }
$this->headersSent = true; $this->headersSent = true;
parent::sendHeaders(); return parent::sendHeaders();
} }
/** /**
@ -99,7 +99,7 @@ class StreamedResponse extends Response
public function sendContent() public function sendContent()
{ {
if ($this->streamed) { if ($this->streamed) {
return; return $this;
} }
$this->streamed = true; $this->streamed = true;
@ -109,6 +109,8 @@ class StreamedResponse extends Response
} }
call_user_func($this->callback); call_user_func($this->callback);
return $this;
} }
/** /**

View File

@ -121,4 +121,15 @@ class StreamedResponseTest extends TestCase
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
$this->assertEquals(204, $response->getStatusCode()); $this->assertEquals(204, $response->getStatusCode());
} }
public function testReturnThis()
{
$response = new StreamedResponse(function () {});
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
$response = new StreamedResponse(function () {});
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
}
} }