|
| 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