Skip to content

Commit

Permalink
[Session] Fixed Backward Compatibility issue with getFlashes()
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Apr 25, 2012
1 parent b7189fd commit 6756f28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/HttpFoundation/Session/Session.php
Expand Up @@ -256,7 +256,11 @@ public function getFlashes()
$return = array();
if ($all) {
foreach ($all as $name => $array) {
$return[$name] = reset($array);
if (is_numeric(key($array))) {
$return[$name] = reset($array);
} else {
$return[$name] = $array;
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php
Expand Up @@ -183,6 +183,21 @@ public function testGetSetFlashes()
$this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());
}

public function testGetFlashesWithArray()
{
$array = array('notice' => 'hello', 'error' => 'none');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlash('foo', $array);
$this->assertEquals(array('foo' => $array), $this->session->getFlashes());
$this->assertEquals(array(), $this->session->getFlashes());

$array = array('hello', 'foo');
$this->assertEquals(array(), $this->session->getFlashes());
$this->session->setFlash('foo', $array);
$this->assertEquals(array('foo' => 'hello'), $this->session->getFlashes());
$this->assertEquals(array(), $this->session->getFlashes());
}

public function testGetSetFlash()
{
$this->assertNull($this->session->getFlash('notice'));
Expand Down

0 comments on commit 6756f28

Please sign in to comment.