[HttpKernel] Fix RequestDataCollector starting the session

This commit is contained in:
Romain Neutron 2016-06-02 18:53:58 +02:00
parent c7f1f7810c
commit ab62dcf3f4
2 changed files with 19 additions and 2 deletions

View File

@ -130,7 +130,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
unset($this->controllers[$request]);
}
if (null !== $session) {
if (null !== $session && $session->isStarted()) {
if ($request->attributes->has('_redirected')) {
$this->data['redirect'] = $session->remove('sf_redirect');
}
@ -291,7 +291,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession()) {
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession() || !$event->getRequest()->getSession()->isStarted()) {
return;
}

View File

@ -11,7 +11,10 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
@ -52,6 +55,20 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
$this->assertSame('application/json', $c->getContentType());
}
public function testKernelResponseDoesNotStartSession()
{
$kernel = $this->getMock(HttpKernelInterface::class);
$request = new Request();
$session = new Session(new MockArraySessionStorage());
$request->setSession($session);
$response = new Response();
$c = new RequestDataCollector();
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertFalse($session->isStarted());
}
/**
* Test various types of controller callables.
*/