public function HttpCacheTest::testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304 in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php \Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304()
File
- vendor/
symfony/ http-kernel/ Tests/ HttpCache/ HttpCacheTest.php, line 636
Class
Namespace
Symfony\Component\HttpKernel\Tests\HttpCacheCode
public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304() {
$this
->setNextResponse();
$this->cacheConfig['default_ttl'] = 2;
$this
->request('GET', '/');
$this
->assertHttpKernelIsCalled();
$this
->assertTraceContains('miss');
$this
->assertTraceContains('store');
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertRegExp('/s-maxage=2/', $this->response->headers
->get('Cache-Control'));
$this
->request('GET', '/');
$this
->assertHttpKernelIsNotCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertTraceContains('fresh');
$this
->assertTraceNotContains('store');
$this
->assertEquals('Hello World', $this->response
->getContent());
// expires the cache
$values = $this
->getMetaStorageValues();
$this
->assertCount(1, $values);
$tmp = unserialize($values[0]);
$tmp[0][1]['date'] = \DateTime::createFromFormat('U', time() - 5)
->format(DATE_RFC2822);
$r = new \ReflectionObject($this->store);
$m = $r
->getMethod('save');
$m
->setAccessible(true);
$m
->invoke($this->store, 'md' . hash('sha256', 'http://localhost/'), serialize($tmp));
$this
->request('GET', '/');
$this
->assertHttpKernelIsCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertTraceContains('stale');
$this
->assertTraceContains('valid');
$this
->assertTraceContains('store');
$this
->assertTraceNotContains('miss');
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertRegExp('/s-maxage=2/', $this->response->headers
->get('Cache-Control'));
$this
->request('GET', '/');
$this
->assertHttpKernelIsNotCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertTraceContains('fresh');
$this
->assertTraceNotContains('store');
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertRegExp('/s-maxage=2/', $this->response->headers
->get('Cache-Control'));
}