bug #10502 [HttpKernel] Fix #10437: Catch exceptions when reloading a no-cache request (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10437
| License       | MIT

Commits
-------

8e3a395 Fix #10437: Catch exceptions when reloading a no-cache request
This commit is contained in:
Fabien Potencier 2014-03-26 08:25:06 +01:00
commit 16434b5611
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);