merged branch drak/session_tests (PR #3360)

Commits
-------

d077ede [HttpFoundation] Increase test coverage.
cbb3e69 [HttpFoundation] Increase test coverage.

Discussion
----------

[HttpFoundation] Increase session test coverage.

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
This commit is contained in:
Fabien Potencier 2012-02-15 11:02:16 +01:00
commit 60846105c3
5 changed files with 71 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

@ -64,6 +64,13 @@ class AttributeBagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('test', $attributeBag->getStorageKey());
}
public function testGetSetName()
{
$this->assertEquals('attributes', $this->bag->getName());
$this->bag->setName('foo');
$this->assertEquals('foo', $this->bag->getName());
}
/**
* @dataProvider attributesProvider
*/

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'));

View File

@ -70,6 +70,16 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value, $this->session->get($key));
}
/**
* @dataProvider setProvider
*/
public function testHas($key, $value)
{
$this->session->set($key, $value);
$this->assertTrue($this->session->has($key));
$this->assertFalse($this->session->has($key.'non_value'));
}
public function testReplace()
{
$this->session->replace(array('happiness' => 'be good', 'symfony' => 'awesome'));
@ -139,6 +149,11 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(333, $this->session->get('migrate'));
}
public function testSave()
{
$this->session->save();
}
public function testGetId()
{
$this->assertEquals('', $this->session->getId());
@ -146,6 +161,11 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->assertNotEquals('', $this->session->getId());
}
public function testGetFlashBag()
{
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag());
}
// deprecated since 2.1, will be removed from 2.3
public function testGetSetFlashes()