Skip to content

Commit 9e6dcf0

Browse files
committed
merged branch beberlei/PDOSessionTest (PR symfony#3462)
Commits ------- 5a6ce20 [Session] Add Test for PDO Session Storage with SQLite in Memory DB. Discussion ---------- [Session] PDO Session Storage tests The PDO Session storage was untested previously. This test is for the 2.0 API. The methods names all changed in the master branch and have to be adjusted when 2.0 is merged into master.
2 parents 8bdd01f + 5a6ce20 commit 9e6dcf0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage;
13+
14+
use Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage;
15+
16+
class PdoSessionStorageTest extends \PHPUnit_Framework_TestCase
17+
{
18+
private $pdo;
19+
20+
protected function setUp()
21+
{
22+
$this->pdo = new \PDO("sqlite::memory:");
23+
$sql = "CREATE TABLE sessions (sess_id VARCHAR(255) PRIMARY KEY, sess_data TEXT, sess_time INTEGER)";
24+
$this->pdo->exec($sql);
25+
}
26+
27+
public function testMultipleInstances()
28+
{
29+
$storage1 = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions'));
30+
$storage1->sessionWrite('foo', 'bar');
31+
32+
$storage2 = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions'));
33+
$this->assertEquals('bar', $storage2->sessionRead('foo'), 'values persist between instances');
34+
}
35+
36+
public function testSessionDestroy()
37+
{
38+
$storage = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions'));
39+
$storage->sessionWrite('foo', 'bar');
40+
$this->assertEquals(1, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
41+
42+
$storage->sessionDestroy('foo');
43+
44+
$this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
45+
}
46+
47+
public function testSessionGC()
48+
{
49+
$storage = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions'));
50+
51+
$storage->sessionWrite('foo', 'bar');
52+
$storage->sessionWrite('baz', 'bar');
53+
54+
$this->assertEquals(2, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
55+
56+
$storage->sessionGC(-1);
57+
$this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
58+
}
59+
}
60+

0 commit comments

Comments
 (0)