Merge branch 'bugfix/virtual-session-storage_pdo_sqlite'
This commit is contained in:
commit
fc8722cd2a
@ -30,6 +30,12 @@ class VirtualSessionStorage extends NativeSessionStorage {
|
|||||||
return true;
|
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());
|
$rawData = $this->saveHandler->read($this->saveHandler->getId());
|
||||||
$sessionData = $this->_serializer->unserialize($rawData);
|
$sessionData = $this->_serializer->unserialize($rawData);
|
||||||
|
|
||||||
|
58
tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
Normal file
58
tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Ratchet\Session\Storage;
|
||||||
|
|
||||||
|
|
||||||
|
use Ratchet\Session\Serialize\PhpHandler;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
|
||||||
|
|
||||||
|
class VirtualSessionStoragePDOTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var VirtualSessionStorage
|
||||||
|
*/
|
||||||
|
protected $_virtualSessionStorage;
|
||||||
|
|
||||||
|
protected $_pathToDB;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$schema = <<<SQL
|
||||||
|
CREATE TABLE `sessions` (
|
||||||
|
`sess_id` VARBINARY(128) NOT NULL PRIMARY KEY,
|
||||||
|
`sess_data` BLOB NOT NULL,
|
||||||
|
`sess_time` INTEGER UNSIGNED NOT NULL,
|
||||||
|
`sess_lifetime` MEDIUMINT NOT NULL
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
$this->_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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user