bug #25077 [Bridge/Twig] Let getFlashes starts the session (MatTheCat)
This PR was merged into the 3.4 branch.
Discussion
----------
[Bridge/Twig] Let getFlashes starts the session
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? |no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #25073
| License | MIT
Commits
-------
a27f9591f5
Let getFlashes starts the session
This commit is contained in:
commit
72a204e2c3
@ -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) {
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user