public function HttpCacheTest::testReplacesCachedResponsesWhenValidationResultsInNon304Response in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php \Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testReplacesCachedResponsesWhenValidationResultsInNon304Response()
File
- vendor/
symfony/ http-kernel/ Tests/ HttpCache/ HttpCacheTest.php, line 810
Class
Namespace
Symfony\Component\HttpKernel\Tests\HttpCacheCode
public function testReplacesCachedResponsesWhenValidationResultsInNon304Response() {
$time = \DateTime::createFromFormat('U', time());
$count = 0;
$this
->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($time, &$count) {
$response->headers
->set('Last-Modified', $time
->format(DATE_RFC2822));
$response->headers
->set('Cache-Control', 'public');
switch (++$count) {
case 1:
$response
->setContent('first response');
break;
case 2:
$response
->setContent('second response');
break;
case 3:
$response
->setContent('');
$response
->setStatusCode(304);
break;
}
});
// first request should fetch from backend and store in cache
$this
->request('GET', '/');
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertEquals('first response', $this->response
->getContent());
// second request is validated, is invalid, and replaces cached entry
$this
->request('GET', '/');
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertEquals('second response', $this->response
->getContent());
// third response is validated, valid, and returns cached entry
$this
->request('GET', '/');
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertEquals('second response', $this->response
->getContent());
$this
->assertEquals(3, $count);
}