[Bridge] [Twig] get and flush only flash sessions you need in getFlashes method

This commit is contained in:
Jordan Samouh 2017-04-11 09:55:14 +02:00 committed by Nicolas Grekas
parent 8807eaf30b
commit 33b044adb1
2 changed files with 11 additions and 5 deletions

View File

@ -176,9 +176,7 @@ class AppVariable
$result = array();
foreach ($types as $type) {
if ($value = $session->getFlashBag()->get($type)) {
$result[$type] = $value;
}
$result[$type] = $session->getFlashBag()->get($type);
}
return $result;

View File

@ -190,7 +190,10 @@ class AppVariableTest extends TestCase
$this->assertEquals(array(), $this->appVariable->getFlashes('this-does-not-exist'));
$flashMessages = $this->setFlashMessages();
$this->assertEquals(array(), $this->appVariable->getFlashes(array('this-does-not-exist')));
$this->assertEquals(
array('this-does-not-exist' => array()),
$this->appVariable->getFlashes(array('this-does-not-exist'))
);
$flashMessages = $this->setFlashMessages();
$this->assertEquals($flashMessages['notice'], $this->appVariable->getFlashes('notice'));
@ -203,7 +206,7 @@ class AppVariableTest extends TestCase
$flashMessages = $this->setFlashMessages();
$this->assertEquals(
array('notice' => $flashMessages['notice']),
array('notice' => $flashMessages['notice'], 'this-does-not-exist' => array()),
$this->appVariable->getFlashes(array('notice', 'this-does-not-exist'))
);
@ -218,6 +221,11 @@ class AppVariableTest extends TestCase
$this->appVariable->getFlashes(array('warning')),
'After getting some flash types (e.g. "notice" and "error"), the rest of flash messages must remain (e.g. "warning").'
);
$this->assertEquals(
array('this-does-not-exist' => array()),
$this->appVariable->getFlashes(array('this-does-not-exist'))
);
}
protected function setRequestStack($request)