/** * 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'); $pdo = new \PDO("sqlite::memory:"); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $pdo->exec(vsprintf("CREATE TABLE %s (%s VARCHAR(255) PRIMARY KEY, %s TEXT, %s INTEGER)", $dbOptions)); $pdo->prepare(vsprintf("INSERT INTO %s (%s, %s, %s) VALUES (?, ?, ?)", $dbOptions))->execute(array($sessionId, base64_encode('_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}'), time())); $component = new SessionProvider($this->getMock($this->getComponentClassString()), new PdoSessionHandler($pdo, $dbOptions), array('auto_start' => 1)); $connection = $this->getMock('Ratchet\\ConnectionInterface'); $headers = $this->getMock('Guzzle\\Http\\Message\\Request', array('getCookie'), array('POST', '/', array())); $headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue($sessionId)); $component->onOpen($connection, $headers); $this->assertEquals('world', $connection->Session->get('hello')); }
public function testGetSubProtocolsGetFromApp() { $mock = $this->getMock('Ratchet\\Tests\\WebSocket\\Stub\\WsMessageComponentInterface'); $mock->expects($this->once())->method('getSubProtocols')->will($this->returnValue(array('hello', 'world'))); $comp = new SessionProvider($mock, new NullSessionHandler()); $this->assertGreaterThanOrEqual(2, count($comp->getSubProtocols())); }
public function testGetSubProtocolsGetFromApp() { $mock = new MockComponent(); $mock->protocols = array('hello', 'world'); $comp = new SessionProvider($mock, new NullSessionHandler()); $this->assertGreaterThanOrEqual(2, count($comp->getSubProtocols())); }