You are here

public function HttpCacheTest::testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpired in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php \Symfony\Component\HttpKernel\Tests\HttpCache\HttpCacheTest::testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpired()

File

vendor/symfony/http-kernel/Tests/HttpCache/HttpCacheTest.php, line 586

Class

HttpCacheTest

Namespace

Symfony\Component\HttpKernel\Tests\HttpCache

Code

public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpired() {
  $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|3)/', $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'));

  // 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('invalid');
  $this
    ->assertTraceContains('store');
  $this
    ->assertEquals('Hello World', $this->response
    ->getContent());
  $this
    ->assertRegExp('/s-maxage=2/', $this->response->headers
    ->get('Cache-Control'));
  $this
    ->setNextResponse();
  $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'));
}