[Session] Fixed Backward Compatibility issue with getFlashes()

This commit is contained in:
William DURAND 2012-04-25 19:34:10 +02:00
parent b7189fd54a
commit 6756f2819d
2 changed files with 20 additions and 1 deletions

View File

@ -256,7 +256,11 @@ class Session implements SessionInterface, \IteratorAggregate, \Countable
$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;
}
}
}

View File

@ -183,6 +183,21 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$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'));