[HttpFoundation] Increase test coverage.
This commit is contained in:
parent
cbb3e69b36
commit
d077edebb4
@ -93,13 +93,10 @@ class AutoExpireFlashBag implements FlashBagInterface
|
|||||||
*/
|
*/
|
||||||
public function get($type, $default = null)
|
public function get($type, $default = null)
|
||||||
{
|
{
|
||||||
if (!$this->has($type)) {
|
$return = $default;
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
$return = null;
|
if (!$this->has($type)) {
|
||||||
if (isset($this->flashes['new'][$type])) {
|
return $return;
|
||||||
unset($this->flashes['new'][$type]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->flashes['display'][$type])) {
|
if (isset($this->flashes['display'][$type])) {
|
||||||
|
@ -22,7 +22,7 @@ use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
|
|||||||
class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
|
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
|
||||||
*/
|
*/
|
||||||
private $bag;
|
private $bag;
|
||||||
|
|
||||||
@ -60,6 +60,20 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('a', $bag->peek('error'));
|
$this->assertEquals('a', $bag->peek('error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetStorageKey()
|
||||||
|
{
|
||||||
|
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
|
||||||
|
$attributeBag = new FlashBag('test');
|
||||||
|
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSetName()
|
||||||
|
{
|
||||||
|
$this->assertEquals('flashes', $this->bag->getName());
|
||||||
|
$this->bag->setName('foo');
|
||||||
|
$this->assertEquals('foo', $this->bag->getName());
|
||||||
|
}
|
||||||
|
|
||||||
public function testPeek()
|
public function testPeek()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->bag->peek('non_existing'));
|
$this->assertNull($this->bag->peek('non_existing'));
|
||||||
@ -116,6 +130,13 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertNull($this->bag->get('notice'));
|
$this->assertNull($this->bag->get('notice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetAll()
|
||||||
|
{
|
||||||
|
$this->bag->setAll(array('a' => 'first', 'b' => 'second'));
|
||||||
|
$this->assertFalse($this->bag->has('a'));
|
||||||
|
$this->assertFalse($this->bag->has('b'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAll()
|
public function testAll()
|
||||||
{
|
{
|
||||||
$this->bag->set('notice', 'Foo');
|
$this->bag->set('notice', 'Foo');
|
||||||
@ -127,4 +148,9 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(array(), $this->bag->all());
|
$this->assertEquals(array(), $this->bag->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testClear()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,20 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($array, $bag->peekAll());
|
$this->assertEquals($array, $bag->peekAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetStorageKey()
|
||||||
|
{
|
||||||
|
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
|
||||||
|
$attributeBag = new FlashBag('test');
|
||||||
|
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSetName()
|
||||||
|
{
|
||||||
|
$this->assertEquals('flashes', $this->bag->getName());
|
||||||
|
$this->bag->setName('foo');
|
||||||
|
$this->assertEquals('foo', $this->bag->getName());
|
||||||
|
}
|
||||||
|
|
||||||
public function testPeek()
|
public function testPeek()
|
||||||
{
|
{
|
||||||
$this->assertNull($this->bag->peek('non_existing'));
|
$this->assertNull($this->bag->peek('non_existing'));
|
||||||
|
Reference in New Issue
Block a user