diff --git a/src/Ratchet/Session/Storage/VirtualSessionStorage.php b/src/Ratchet/Session/Storage/VirtualSessionStorage.php index 9fb0eb7..daa10bb 100644 --- a/src/Ratchet/Session/Storage/VirtualSessionStorage.php +++ b/src/Ratchet/Session/Storage/VirtualSessionStorage.php @@ -30,6 +30,12 @@ class VirtualSessionStorage extends NativeSessionStorage { return true; } + // You have to call Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler::open() to use + // pdo_sqlite (and possible pdo_*) as session storage, if you are using a DSN string instead of a \PDO object + // in the constructor. The method arguments are filled with the values, which are also used by the symfony + // framework in this case. This must not be the best choice, but it works. + $this->saveHandler->open(session_save_path(), session_name()); + $rawData = $this->saveHandler->read($this->saveHandler->getId()); $sessionData = $this->_serializer->unserialize($rawData); diff --git a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php new file mode 100644 index 0000000..9909bce --- /dev/null +++ b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php @@ -0,0 +1,58 @@ +_pathToDB = tempnam(sys_get_temp_dir(), 'SQ3');; + $dsn = 'sqlite:' . $this->_pathToDB; + + $pdo = new \PDO($dsn); + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $pdo->exec($schema); + $pdo = null; + + $sessionHandler = new PdoSessionHandler($dsn); + $serializer = new PhpHandler(); + $this->_virtualSessionStorage = new VirtualSessionStorage($sessionHandler, 'foobar', $serializer); + $this->_virtualSessionStorage->registerBag(new FlashBag()); + $this->_virtualSessionStorage->registerBag(new AttributeBag()); + } + + public function tearDown() + { + unlink($this->_pathToDB); + } + + public function testStartWithDSN() + { + $this->_virtualSessionStorage->start(); + + $this->assertTrue($this->_virtualSessionStorage->isStarted()); + } + + +}