HttpCache: New test for revalidating responses with an expired TTL
This commit is contained in:
parent
0259bedec1
commit
067ab52ba0
@ -809,6 +809,42 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceNotContains('miss');
|
||||
}
|
||||
|
||||
public function testServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$this->setNextResponse(200, array(), 'Hello World', function (Request $request, Response $response) use ($time) {
|
||||
$response->setSharedMaxAge(10);
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
});
|
||||
|
||||
// prime the cache
|
||||
$this->request('GET', '/');
|
||||
|
||||
// next request before s-maxage has expired: Serve from cache
|
||||
// without hitting the backend
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
sleep(15); // expire the cache
|
||||
|
||||
$that = $this;
|
||||
|
||||
$this->setNextResponse(304, array(), '', function (Request $request, Response $response) use ($time, $that) {
|
||||
$that->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE'));
|
||||
});
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('stale');
|
||||
$this->assertTraceContains('valid');
|
||||
}
|
||||
|
||||
public function testReplacesCachedResponsesWhenValidationResultsInNon304Response()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
Reference in New Issue
Block a user