diff --git a/src/Symfony/Bridge/Twig/AppVariable.php b/src/Symfony/Bridge/Twig/AppVariable.php index e8e69d0ee3d68..54a785c0a4336 100644 --- a/src/Symfony/Bridge/Twig/AppVariable.php +++ b/src/Symfony/Bridge/Twig/AppVariable.php @@ -156,10 +156,9 @@ public function getDebug() */ 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 f6c678a918072..27eca0c44a74a 100644 --- a/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php +++ b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php @@ -174,13 +174,8 @@ public function testGetFlashesWithNoRequest() */ 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 @@ protected function setTokenStorage($user) $token->method('getUser')->willReturn($user); } - private function setFlashMessages() + private function setFlashMessages($sessionHasStarted = true) { $flashMessages = array( 'notice' => array('Notice #1 message'), @@ -269,7 +264,7 @@ private function setFlashMessages() $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();
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: