[HttpFoundation] Increase test coverage.

This commit is contained in:
Drak 2012-02-14 21:41:27 +05:45
parent cbb3e69b36
commit d077edebb4
3 changed files with 44 additions and 7 deletions

View File

@ -93,13 +93,10 @@ class AutoExpireFlashBag implements FlashBagInterface
*/
public function get($type, $default = null)
{
if (!$this->has($type)) {
return $default;
}
$return = $default;
$return = null;
if (isset($this->flashes['new'][$type])) {
unset($this->flashes['new'][$type]);
if (!$this->has($type)) {
return $return;
}
if (isset($this->flashes['display'][$type])) {

View File

@ -22,7 +22,7 @@ use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
*/
private $bag;
@ -60,6 +60,20 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
$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()
{
$this->assertNull($this->bag->peek('non_existing'));
@ -116,6 +130,13 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
$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()
{
$this->bag->set('notice', 'Foo');
@ -127,4 +148,9 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $this->bag->all());
}
public function testClear()
{
$this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear());
}
}

View File

@ -55,6 +55,20 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase
$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()
{
$this->assertNull($this->bag->peek('non_existing'));