diff --git a/src/Symfony/Bridge/Twig/AppVariable.php b/src/Symfony/Bridge/Twig/AppVariable.php index e8e69d0ee3..54a785c0a4 100644 --- a/src/Symfony/Bridge/Twig/AppVariable.php +++ b/src/Symfony/Bridge/Twig/AppVariable.php @@ -156,10 +156,9 @@ class AppVariable */ public function getFlashes($types = null) { - // needed to avoid starting the session automatically when looking for flash messages try { $session = $this->getSession(); - if (null === $session || !$session->isStarted()) { + if (null === $session) { return array(); } } catch (\RuntimeException $e) { diff --git a/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php index f6c678a918..27eca0c44a 100644 --- a/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php +++ b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php @@ -174,13 +174,8 @@ class AppVariableTest extends TestCase */ public function testGetFlashesWithNoSessionStarted() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); - $request->method('getSession')->willReturn($session); - - $this->setRequestStack($request); - - $this->assertEquals(array(), $this->appVariable->getFlashes()); + $flashMessages = $this->setFlashMessages(false); + $this->assertEquals($flashMessages, $this->appVariable->getFlashes()); } /** @@ -258,7 +253,7 @@ class AppVariableTest extends TestCase $token->method('getUser')->willReturn($user); } - private function setFlashMessages() + private function setFlashMessages($sessionHasStarted = true) { $flashMessages = array( 'notice' => array('Notice #1 message'), @@ -269,7 +264,7 @@ class AppVariableTest extends TestCase $flashBag->initialize($flashMessages); $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock(); - $session->method('isStarted')->willReturn(true); + $session->method('isStarted')->willReturn($sessionHasStarted); $session->method('getFlashBag')->willReturn($flashBag); $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();