Kraken\_Unit\Network\Http\Component\Session\HttpSessionTest::testApiHandleConnect_AttachesSessionHandler PHP Метод

testApiHandleConnect_AttachesSessionHandler() публичный Метод

    public function testApiHandleConnect_AttachesSessionHandler()
    {
        if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) {
            $this->markTestSkipped('Session test requires PDO and pdo_sqlite');
        }
        $sessionId = md5('testSession');
        $dbOptions = ['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:{}');
        $conn = $this->getMock(NetworkConnection::class, [], [], '', false);
        $server = $this->createServer();
        $component = $this->createComponent(['handleConnect']);
        $component->expects($this->once())->method('handleConnect')->with($conn);
        $session = $this->createSession($server, $component, $pdoHandler, ['auto_start' => 1]);
        $req = $this->getMock(HttpRequest::class, ['getCookie'], ['POST', '/', []]);
        $req->expects($this->once())->method('getCookie')->with(ini_get('session.name'))->will($this->returnValue($sessionId));
        $conn->WebSocket = new StdClass();
        $conn->WebSocket->request = $req;
        $session->handleConnect($conn);
        $this->assertSame('world', $conn->Session->get('hello'));
    }