10000 merged branch drak/session_tests (PR #3360) · symfony/symfony@6084610 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6084610

Browse files
committed
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: -
2 parents e7adf54 + d077ede commit 6084610

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ public function peekAll()
9393
*/
9494
public function get($type, $default = null)
9595
{
96-
if (!$this->has($type)) {
97-
return $default;
98-
}
96+
$return = $default;
9997

100-
$return = null;
101-
if (isset($this->flashes['new'][$type])) {
102-
unset($this->flashes['new'][$type]);
98+
if (!$this->has($type)) {
99+
return $return;
103100
}
104101

105102
if (isset($this->flashes['display'][$type])) {

tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/AttributeBagTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function testGetStorageKey()
6464
$this->assertEquals('test', $attributeBag->getStorageKey());
6565
}
6666

67+
public function testGetSetName()
68+
{
69+
$this->assertEquals('attributes', $this->bag->getName());
70+
$this->bag->setName('foo');
71+
$this->assertEquals('foo', $this->bag->getName());
72+
}
73+
6774
/**
6875
* @dataProvider attributesProvider
6976
*/

tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase
2323
{
2424
/**
25-
* @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
25+
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
2626
*/
2727
private $bag;
2828

@@ -60,6 +60,20 @@ public function testInitialize()
6060
$this->assertEquals('a', $bag->peek('error'));
6161
}
6262

63+
public function testGetStorageKey()
64+
{
65+
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
66+
$attributeBag = new FlashBag('test');
67+
$this->assertEquals('test', $attributeBag->getStorageKey());
68+
}
69+
70+
public function testGetSetName()
71+
{
72+
$this->assertEquals('flashes', $this->bag->getName());
73+
$this->bag->setName('foo');
74+
$this->assertEquals('foo', $this->bag->getName());
75+
}
76+
6377
public function testPeek()
6478
{
6579
$this->assertNull($this->bag->peek('non_existing'));
@@ -116,6 +130,13 @@ public function testGet()
116130
$this->assertNull($this->bag->get('notice'));
117131
}
118132

133+
public function testSetAll()
134+
{
135+
$this->bag->setAll(array('a' => 'first', 'b' => 'second'));
136+
$this->assertFalse($this->bag->has('a'));
137+
$this->assertFalse($this->bag->has('b'));
138+
}
139+
119140
public function testAll()
120141
{
121142
$this->bag->set('notice', 'Foo');
@@ -127,4 +148,9 @@ public function testAll()
127148

128149
$this->assertEquals(array(), $this->bag->all());
129150
}
151+
152+
public function testClear()
153+
{
154+
$this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear());
155+
}
130156
}

tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public function testInitialize()
5555
$this->assertEquals($array, $bag->peekAll());
5656
}
5757

58+
public function testGetStorageKey()
59+
{
60+
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
61+
$attributeBag = new FlashBag('test');
62+
$this->assertEquals('test', $attributeBag->getStorageKey());
63+
}
64+
65+
public function testGetSetName()
66+
{
67+
$this->assertEquals('flashes', $this->bag->getName());
68+
$this->bag->setName('foo');
69+
$this->assertEquals('foo', $this->bag->getName());
70+
}
71+
5872
public function testPeek()
5973
{
6074
$this->assertNull($this->bag->peek('non_existing'));

tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ public function testSet($key, $value)
7070
$this->assertEquals($value, $this->session->get($key));
7171
}
7272

73+
/**
74+
* @dataProvider setProvider
75+
*/
76+
public function testHas($key, $value)
77+
{
78+
$this->session->set($key, $value);
79+
$this->assertTrue($this->session->has($key));
80+
$this->assertFalse($this->session->has($key.'non_value'));
81+
}
82+
7383
public function testReplace()
7484
{
7585
$this->session->replace(array('happiness' => 'be good', 'symfony' => 'awesome'));
@@ -139,13 +149,23 @@ public function testMigrateDestroy()
139149
$this->assertEquals(333, $this->session->get('migrate'));
140150
}
141151

152+
public function testSave()
153+
{
154+
$this->session->save();
155+
}
156+
142157
public function testGetId()
143158
{
144159
$this->assertEquals('', $this->session->getId());
145160
$this->session->start();
146161
$this->assertNotEquals('', $this->session->getId());
147162
}
148163

164+
public function testGetFlashBag()
165+
{
166+
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag());
167+
}
168+
149169
// deprecated since 2.1, will be removed from 2.3
150170

151171
public function testGetSetFlashes()

0 commit comments

Comments
 (0)
0