Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Session] Add Test for PDO Session Storage with SQLite in Memory DB.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/PdoSessionStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; | ||
|
||
use Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage; | ||
|
||
class PdoSessionStorageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $pdo; | ||
|
||
protected function setUp() | ||
{ | ||
$this->pdo = new \PDO("sqlite::memory:"); | ||
$sql = "CREATE TABLE sessions (sess_id VARCHAR(255) PRIMARY KEY, sess_data TEXT, sess_time INTEGER)"; | ||
$this->pdo->exec($sql); | ||
} | ||
|
||
public function testMultipleInstances() | ||
{ | ||
$storage1 = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions')); | ||
$storage1->sessionWrite('foo', 'bar'); | ||
|
||
$storage2 = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions')); | ||
$this->assertEquals('bar', $storage2->sessionRead('foo'), 'values persist between instances'); | ||
} | ||
|
||
public function testSessionDestroy() | ||
{ | ||
$storage = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions')); | ||
$storage->sessionWrite('foo', 'bar'); | ||
$this->assertEquals(1, count($this->pdo->query('SELECT * FROM sessions')->fetchAll())); | ||
|
||
$storage->sessionDestroy('foo'); | ||
|
||
$this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll())); | ||
} | ||
|
||
public function testSessionGC() | ||
{ | ||
$storage = new PdoSessionStorage($this->pdo, array(), array('db_table' => 'sessions')); | ||
|
||
$storage->sessionWrite('foo', 'bar'); | ||
$storage->sessionWrite('baz', 'bar'); | ||
|
||
$this->assertEquals(2, count($this->pdo->query('SELECT * FROM sessions')->fetchAll())); | ||
|
||
$storage->sessionGC(-1); | ||
$this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll())); | ||
} | ||
} | ||
|