Skip to content

Commit 0850b48

Browse files
committed
bug #27937 [HttpFoundation] reset callback on StreamedResponse when setNotModified() is called (rubencm)
This PR was merged into the 2.8 branch. Discussion ---------- [HttpFoundation] reset callback on StreamedResponse when setNotModified() is called | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27924 | License | MIT | Doc PR | No Commits ------- 51a49c7f78 [HttpFoundation] reset callback on StreamedResponse when setNotModified() is called
2 parents 9c69e10 + 3045ecb commit 0850b48

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

StreamedResponse.php

+12
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,16 @@ public function getContent()
134134
{
135135
return false;
136136
}
137+
138+
/**
139+
* {@inheritdoc}
140+
*
141+
* @return $this
142+
*/
143+
public function setNotModified()
144+
{
145+
$this->setCallback(function () {});
146+
147+
return parent::setNotModified();
148+
}
137149
}

Tests/ResponseTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testMustRevalidateWithProxyRevalidateCacheControlHeader()
126126

127127
public function testSetNotModified()
128128
{
129-
$response = new Response();
129+
$response = new Response('foo');
130130
$modified = $response->setNotModified();
131131
$this->assertObjectHasAttribute('headers', $modified);
132132
$this->assertObjectHasAttribute('content', $modified);
@@ -135,6 +135,11 @@ public function testSetNotModified()
135135
$this->assertObjectHasAttribute('statusText', $modified);
136136
$this->assertObjectHasAttribute('charset', $modified);
137137
$this->assertEquals(304, $modified->getStatusCode());
138+
139+
ob_start();
140+
$modified->sendContent();
141+
$string = ob_get_clean();
142+
$this->assertEmpty($string);
138143
}
139144

140145
public function testIsSuccessful()

Tests/StreamedResponseTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,22 @@ public function testReturnThis()
132132
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
133133
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
134134
}
135+
136+
public function testSetNotModified()
137+
{
138+
$response = new StreamedResponse(function () { echo 'foo'; });
139+
$modified = $response->setNotModified();
140+
$this->assertObjectHasAttribute('headers', $modified);
141+
$this->assertObjectHasAttribute('content', $modified);
142+
$this->assertObjectHasAttribute('version', $modified);
143+
$this->assertObjectHasAttribute('statusCode', $modified);
144+
$this->assertObjectHasAttribute('statusText', $modified);
145+
$this->assertObjectHasAttribute('charset', $modified);
146+
$this->assertEquals(304, $modified->getStatusCode());
147+
148+
ob_start();
149+
$modified->sendContent();
150+
$string = ob_get_clean();
151+
$this->assertEmpty($string);
152+
}
135153
}

0 commit comments

Comments
 (0)