Skip to content

Commit

Permalink
[HttpFoundation] reset callback on StreamedResponse when setNotModifi…
Browse files Browse the repository at this point in the history
…ed() is called
  • Loading branch information
rubencm committed Jul 13, 2018
1 parent 3b90bc7 commit 51a49c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Symfony/Component/HttpFoundation/StreamedResponse.php
Expand Up @@ -134,4 +134,16 @@ public function getContent()
{
return false;
}

/**
* {@inheritdoc}
*
* @return $this
*/
public function setNotModified()
{
$this->setCallback(function () {});

return parent::setNotModified();
}
}
7 changes: 6 additions & 1 deletion src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Expand Up @@ -126,7 +126,7 @@ public function testMustRevalidateWithProxyRevalidateCacheControlHeader()

public function testSetNotModified()
{
$response = new Response();
$response = new Response('foo');
$modified = $response->setNotModified();
$this->assertObjectHasAttribute('headers', $modified);
$this->assertObjectHasAttribute('content', $modified);
Expand All @@ -135,6 +135,11 @@ public function testSetNotModified()
$this->assertObjectHasAttribute('statusText', $modified);
$this->assertObjectHasAttribute('charset', $modified);
$this->assertEquals(304, $modified->getStatusCode());

ob_start();
$modified->sendContent();
$string = ob_get_clean();
$this->assertEmpty($string);
}

public function testIsSuccessful()
Expand Down
Expand Up @@ -132,4 +132,22 @@ public function testReturnThis()
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
}

public function testSetNotModified()
{
$response = new StreamedResponse(function () { echo 'foo'; });
$modified = $response->setNotModified();
$this->assertObjectHasAttribute('headers', $modified);
$this->assertObjectHasAttribute('content', $modified);
$this->assertObjectHasAttribute('version', $modified);
$this->assertObjectHasAttribute('statusCode', $modified);
$this->assertObjectHasAttribute('statusText', $modified);
$this->assertObjectHasAttribute('charset', $modified);
$this->assertEquals(304, $modified->getStatusCode());

ob_start();
$modified->sendContent();
$string = ob_get_clean();
$this->assertEmpty($string);
}
}

0 comments on commit 51a49c7

Please sign in to comment.