aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/cboden/ratchet/tests/unit/Session
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/cboden/ratchet/tests/unit/Session
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/cboden/ratchet/tests/unit/Session')
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Session/Serialize/PhpHandlerTest.php43
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Session/SessionComponentTest.php124
-rw-r--r--assets/php/vendor/cboden/ratchet/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php53
3 files changed, 220 insertions, 0 deletions
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Session/Serialize/PhpHandlerTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Session/Serialize/PhpHandlerTest.php
new file mode 100644
index 0000000..4acf5bc
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Session/Serialize/PhpHandlerTest.php
@@ -0,0 +1,43 @@
+<?php
+namespace Ratchet\Session\Serialize;
+use Ratchet\Session\Serialize\PhpHandler;
+
+/**
+ * @covers Ratchet\Session\Serialize\PhpHandler
+ */
+class PhpHandlerTest extends \PHPUnit_Framework_TestCase {
+ protected $_handler;
+
+ public function setUp() {
+ $this->_handler = new PhpHandler;
+ }
+
+ public function serializedProvider() {
+ return array(
+ array(
+ '_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}'
+ , array(
+ '_sf2_attributes' => array(
+ 'hello' => 'world'
+ , 'last' => 1332872102
+ )
+ , '_sf2_flashes' => array()
+ )
+ )
+ );
+ }
+
+ /**
+ * @dataProvider serializedProvider
+ */
+ public function testUnserialize($in, $expected) {
+ $this->assertEquals($expected, $this->_handler->unserialize($in));
+ }
+
+ /**
+ * @dataProvider serializedProvider
+ */
+ public function testSerialize($serialized, $original) {
+ $this->assertEquals($serialized, $this->_handler->serialize($original));
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Session/SessionComponentTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Session/SessionComponentTest.php
new file mode 100644
index 0000000..ebfdde4
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Session/SessionComponentTest.php
@@ -0,0 +1,124 @@
+<?php
+namespace Ratchet\Session;
+use Ratchet\AbstractMessageComponentTestCase;
+use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
+use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
+
+/**
+ * @covers Ratchet\Session\SessionProvider
+ * @covers Ratchet\Session\Storage\VirtualSessionStorage
+ * @covers Ratchet\Session\Storage\Proxy\VirtualProxy
+ */
+class SessionProviderTest extends AbstractMessageComponentTestCase {
+ public function setUp() {
+ if (!class_exists('Symfony\Component\HttpFoundation\Session\Session')) {
+ return $this->markTestSkipped('Dependency of Symfony HttpFoundation failed');
+ }
+
+ parent::setUp();
+ $this->_serv = new SessionProvider($this->_app, new NullSessionHandler);
+ }
+
+ public function tearDown() {
+ ini_set('session.serialize_handler', 'php');
+ }
+
+ public function getConnectionClassString() {
+ return '\Ratchet\ConnectionInterface';
+ }
+
+ public function getDecoratorClassString() {
+ return '\Ratchet\NullComponent';
+ }
+
+ public function getComponentClassString() {
+ return '\Ratchet\Http\HttpServerInterface';
+ }
+
+ public function classCaseProvider() {
+ return array(
+ array('php', 'Php')
+ , array('php_binary', 'PhpBinary')
+ );
+ }
+
+ /**
+ * @dataProvider classCaseProvider
+ */
+ public function testToClassCase($in, $out) {
+ $ref = new \ReflectionClass('\\Ratchet\\Session\\SessionProvider');
+ $method = $ref->getMethod('toClassCase');
+ $method->setAccessible(true);
+
+ $component = new SessionProvider($this->getMock($this->getComponentClassString()), $this->getMock('\SessionHandlerInterface'));
+ $this->assertEquals($out, $method->invokeArgs($component, array($in)));
+ }
+
+ /**
+ * I think I have severely butchered this test...it's not so much of a unit test as it is a full-fledged component test
+ */
+ public function testConnectionValueFromPdo() {
+ if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) {
+ return $this->markTestSkipped('Session test requires PDO and pdo_sqlite');
+ }
+
+ $sessionId = md5('testSession');
+
+ $dbOptions = array(
+ 'db_table' => 'sessions'
+ , 'db_id_col' => 'sess_id'
+ , 'db_data_col' => 'sess_data'
+ , 'db_time_col' => 'sess_time'
+ , 'db_lifetime_col' => 'sess_lifetime'
+ );
+
+ $pdo = new \PDO("sqlite::memory:");
+ $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
+ $pdo->exec(vsprintf("CREATE TABLE %s (%s TEXT NOT NULL PRIMARY KEY, %s BLOB NOT NULL, %s INTEGER NOT NULL, %s INTEGER)", $dbOptions));
+
+ $pdoHandler = new PdoSessionHandler($pdo, $dbOptions);
+ $pdoHandler->write($sessionId, '_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}');
+
+ $component = new SessionProvider($this->getMock($this->getComponentClassString()), $pdoHandler, array('auto_start' => 1));
+ $connection = $this->getMock('Ratchet\\ConnectionInterface');
+
+ $headers = $this->getMock('Psr\Http\Message\RequestInterface');
+ $headers->expects($this->once())->method('getHeader')->will($this->returnValue([ini_get('session.name') . "={$sessionId};"]));
+
+ $component->onOpen($connection, $headers);
+
+ $this->assertEquals('world', $connection->Session->get('hello'));
+ }
+
+ protected function newConn() {
+ $conn = $this->getMock('Ratchet\ConnectionInterface');
+
+ $headers = $this->getMock('Psr\Http\Message\Request', array('getCookie'), array('POST', '/', array()));
+ $headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue(null));
+
+ return $conn;
+ }
+
+ public function testOnMessageDecorator() {
+ $message = "Database calls are usually blocking :(";
+ $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message);
+ $this->_serv->onMessage($this->_conn, $message);
+ }
+
+ public function testRejectInvalidSeralizers() {
+ if (!function_exists('wddx_serialize_value')) {
+ $this->markTestSkipped();
+ }
+
+ ini_set('session.serialize_handler', 'wddx');
+ $this->setExpectedException('\RuntimeException');
+ new SessionProvider($this->getMock($this->getComponentClassString()), $this->getMock('\SessionHandlerInterface'));
+ }
+
+ protected function doOpen($conn) {
+ $request = $this->getMock('Psr\Http\Message\RequestInterface');
+ $request->expects($this->any())->method('getHeader')->will($this->returnValue([]));
+
+ $this->_serv->onOpen($conn, $request);
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php b/assets/php/vendor/cboden/ratchet/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
new file mode 100644
index 0000000..2727484
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
@@ -0,0 +1,53 @@
+<?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() {
+ if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) {
+ return $this->markTestSkipped('Session test requires PDO and pdo_sqlite');
+ }
+
+ $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());
+ }
+}