[HttpFoudation] CS, more tests and some optimization.
This commit is contained in:
parent
b0466e8bb4
commit
910b5c7f83
|
@ -46,9 +46,9 @@ class SessionHelper extends Helper
|
|||
return $this->session->get($name, $default);
|
||||
}
|
||||
|
||||
public function getFlash($name, $default = null)
|
||||
public function getFlash($name, array $default = array())
|
||||
{
|
||||
return $this->session->getFlashBag()->get($name);
|
||||
return $this->session->getFlashBag()->get($name, $default);
|
||||
}
|
||||
|
||||
public function getFlashes()
|
||||
|
|
|
@ -139,8 +139,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
|||
*/
|
||||
public function set($type, $messages)
|
||||
{
|
||||
$messages = (array)$messages;
|
||||
$this->flashes['new'][$type] = $messages;
|
||||
$this->flashes['new'][$type] = (array)$messages;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,9 +171,6 @@ class AutoExpireFlashBag implements FlashBagInterface
|
|||
*/
|
||||
public function clear()
|
||||
{
|
||||
$return = $this->all();
|
||||
$this->flashes = array('display' => array(), 'new' => array());
|
||||
|
||||
return $return;
|
||||
return $this->all();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,8 +121,7 @@ class FlashBag implements FlashBagInterface
|
|||
*/
|
||||
public function set($type, $messages)
|
||||
{
|
||||
$messages = (array)$messages;
|
||||
$this->flashes[$type] = $messages;
|
||||
$this->flashes[$type] = (array) $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -310,5 +310,4 @@ class Session implements SessionInterface
|
|||
{
|
||||
return $this->getBag($this->flashName)->clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -150,6 +150,6 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testClear()
|
||||
{
|
||||
$this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear());
|
||||
$this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,13 +175,21 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
|||
$this->session->setFlashes($array);
|
||||
$this->assertEquals($array, $this->session->getFlashes());
|
||||
$this->assertEquals(array(), $this->session->getFlashes());
|
||||
$this->session->getFlashBag()->add('notice', 'foo');
|
||||
|
||||
// test that BC works by only retrieving the first added.
|
||||
$this->session->getFlashBag()->add('notice', 'foo2');
|
||||
$this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());
|
||||
}
|
||||
|
||||
public function testGetSetFlash()
|
||||
{
|
||||
$this->assertNull($this->session->getFlash('notice'));
|
||||
$this->assertEquals('default', $this->session->getFlash('notice', 'default'));
|
||||
$this->session->setFlash('notice', 'foo');
|
||||
$this->session->getFlashBag()->add('notice', 'foo');
|
||||
$this->session->getFlashBag()->add('notice', 'foo2');
|
||||
|
||||
// test that BC works by only retrieving the first added.
|
||||
$this->assertEquals('foo', $this->session->getFlash('notice'));
|
||||
$this->assertNull($this->session->getFlash('notice'));
|
||||
}
|
||||
|
|
Reference in New Issue