public function testInvalidatesCachedResponsesOnPost() {
$this
->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
if ('GET' == $request
->getMethod()) {
$response
->setStatusCode(200);
$response->headers
->set('Cache-Control', 'public, max-age=500');
$response
->setContent('Hello World');
}
elseif ('POST' == $request
->getMethod()) {
$response
->setStatusCode(303);
$response->headers
->set('Location', '/');
$response->headers
->remove('Cache-Control');
$response
->setContent('');
}
});
// build initial request to enter into the cache
$this
->request('GET', '/');
$this
->assertHttpKernelIsCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertTraceContains('miss');
$this
->assertTraceContains('store');
// make sure it is valid
$this
->request('GET', '/');
$this
->assertHttpKernelIsNotCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertTraceContains('fresh');
// now POST to same URL
$this
->request('POST', '/helloworld');
$this
->assertHttpKernelIsCalled();
$this
->assertEquals('/', $this->response->headers
->get('Location'));
$this
->assertTraceContains('invalidate');
$this
->assertTraceContains('pass');
$this
->assertEquals('', $this->response
->getContent());
// now make sure it was actually invalidated
$this
->request('GET', '/');
$this
->assertHttpKernelIsCalled();
$this
->assertEquals(200, $this->response
->getStatusCode());
$this
->assertEquals('Hello World', $this->response
->getContent());
$this
->assertTraceContains('stale');
$this
->assertTraceContains('invalid');
$this
->assertTraceContains('store');
}