bug #22368 [Bridge] [Twig] get and flush only flash sessions you need in getFlashes method (jordscream)
This PR was squashed before being merged into the 3.3-dev branch (closes #22368).
Discussion
----------
[Bridge] [Twig] get and flush only flash sessions you need in getFlashes method
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks? | no ?!
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass? | yes
| Fixed tickets | #22359
| License | MIT
| Doc PR | symfony/symfony-docs
@xabbuh comments about empty array to return
Commits
-------
33b044a
[Bridge] [Twig] get and flush only flash sessions you need in getFlashes method
This commit is contained in:
commit
35afac00a0
@ -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;
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user