Fix #10437: Catch exceptions when reloading a no-cache request

This commit is contained in:
Romain Neutron 2014-03-20 14:55:59 +01:00 committed by Fabien Potencier
parent 1a26d28581
commit 8e3a3951e3
3 changed files with 14 additions and 2 deletions

View File

@ -308,7 +308,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
if ($this->options['allow_reload'] && $request->isNoCache()) {
$this->record($request, 'reload');
return $this->fetch($request);
return $this->fetch($request, $catch);
}
try {

View File

@ -934,6 +934,17 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertExceptionsAreCaught();
}
public function testShouldCatchExceptionsWhenReloadingAndNoCacheRequest()
{
$this->catchExceptions();
$this->setNextResponse();
$this->cacheConfig['allow_reload'] = true;
$this->request('GET', '/', array(), array(), false, array('Pragma' => 'no-cache'));
$this->assertExceptionsAreCaught();
}
public function testShouldNotCatchExceptions()
{
$this->catchExceptions(false);

View File

@ -107,7 +107,7 @@ class HttpCacheTestCase extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->kernel->isCatchingExceptions());
}
public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false)
public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false, $headers = array())
{
if (null === $this->kernel) {
throw new \LogicException('You must call setNextResponse() before calling request().');
@ -122,6 +122,7 @@ class HttpCacheTestCase extends \PHPUnit_Framework_TestCase
$this->esi = $esi ? new Esi() : null;
$this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig);
$this->request = Request::create($uri, $method, array(), $cookies, array(), $server);
$this->request->headers->add($headers);
$this->response = $this->cache->handle($this->request, HttpKernelInterface::MASTER_REQUEST, $this->catch);