$this->
setNextResponse(200,
['Cache-Control' => 'public, no-cache, max-age=10', 'ETag' => 'some-etag'
], 'OK'
);
$this->
request('GET', '/'
); // warm the cache
sleep(5
);
$this->
setNextResponse(304,
['Cache-Control' => 'public, no-cache, max-age=10', 'ETag' => 'some-etag'
]);
$this->
request('GET', '/'
);
$this->
assertHttpKernelIsCalled(); // no-cache -> MUST have revalidated at origin
$this->
assertTraceContains('valid'
);
$this->
assertEquals('OK',
$this->response->
getContent());
$this->
assertEquals(0,
$this->response->
getAge());
} public function testCachesResponsesWithAnExpirationHeader() { $time = \DateTimeImmutable::
createFromFormat('U',
time() + 5
);
$this->
setNextResponse(200,
['Cache-Control' => 'public', 'Expires' =>
$time->
format(\DATE_RFC2822
)]);
$this->
request('GET', '/'
);
$this->
assertEquals(200,
$this->response->
getStatusCode());
$this->
assertEquals('Hello World',
$this->response->
getContent());
$this->
assertNotNull($this->response->headers->
get('Date'
));