diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php index 95592f7505..d0360c3e2c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php @@ -67,13 +67,10 @@ class TestSessionListener implements EventSubscriberInterface return; } - if ($session = $event->getRequest()->getSession()) { - if ($session->isStarted()) { - $session->save(); - } - + $session = $event->getRequest()->getSession(); + if ($session && $session->isStarted()) { + $session->save(); $params = session_get_cookie_params(); - $event->getResponse()->headers->setCookie(new Cookie($session->getName(), $session->getId(), 0 === $params['lifetime'] ? 0 : time() + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly'])); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php index cfaf8e80a9..2c91254eb3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * SessionListenerTest. @@ -26,7 +27,14 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent; */ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase { + /** + * @var TestSessionListener + */ private $listener; + + /** + * @var SessionInterface + */ private $session; protected function setUp() @@ -58,6 +66,8 @@ class TestSessionListenerTest extends \PHPUnit_Framework_TestCase public function testDoesNotDeleteCookieIfUsingSessionLifetime() { + $this->sessionHasBeenStarted(); + $params = session_get_cookie_params(); session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']);