gc example


  #[\ReturnTypeWillChange]   public function destroy($session_id) {
    return $this->wrappedSessionHandler->destroy($session_id);
  }

  /** * {@inheritdoc} */
  #[\ReturnTypeWillChange]   public function gc($max_lifetime) {
    return $this->wrappedSessionHandler->gc($max_lifetime);
  }

  /** * {@inheritdoc} */
  #[\ReturnTypeWillChange]   public function open($save_path$session_id) {
    return $this->wrappedSessionHandler->open($save_path$session_id);
  }

  /** * {@inheritdoc} */
->expects($this->once())
            ->method('delete')
            ->with(self::PREFIX.'id')
            ->willReturn(true)
        ;

        $this->assertTrue($this->storage->destroy('id'));
    }

    public function testGcSession()
    {
        $this->assertIsInt($this->storage->gc(123));
    }

    /** * @dataProvider getOptionFixtures */
    public function testSupportedOptions($options$supported)
    {
        try {
            new MemcachedSessionHandler($this->memcached, $options);
            $this->assertTrue($supported);
        } catch (\InvalidArgumentException $e) {
            
    {
        return $this->handler->write($sessionId$data);
    }

    public function destroy(#[\SensitiveParameter] string $sessionId): bool     {
        return $this->handler->destroy($sessionId);
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->handler->gc($maxlifetime);
    }

    public function validateId(#[\SensitiveParameter] string $sessionId): bool     {
        return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
    }

    public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId$data) : $this->write($sessionId$data);
    }
}
$this->assertTrue($proxy->write('id', 'data'));
        $this->assertTrue($proxy->destroy('id'));
    }

    public function testGc()
    {
        $handler = $this->createMock(\SessionHandlerInterface::class);
        $handler->expects($this->once())->method('gc')
            ->with(123)->willReturn(1);
        $proxy = new StrictSessionHandler($handler);

        $this->assertSame(1, $proxy->gc(123));
    }
}
public function testDestroySession()
    {
        $this->redisClient->set(self::PREFIX.'id', 'foo');

        $this->assertTrue((bool) $this->redisClient->exists(self::PREFIX.'id'));
        $this->assertTrue($this->storage->destroy('id'));
        $this->assertFalse((bool) $this->redisClient->exists(self::PREFIX.'id'));
    }

    public function testGcSession()
    {
        $this->assertIsInt($this->storage->gc(123));
    }

    public function testUpdateTimestamp()
    {
        $lowTtl = 10;

        $this->redisClient->setex(self::PREFIX.'id', $lowTtl, 'foo');
        $this->storage->updateTimestamp('id', 'data');

        $this->assertGreaterThan($lowTtl$this->redisClient->ttl(self::PREFIX.'id'));
    }

    
$marshallingSessionHandler->destroy('session_id');
    }

    public function testGc()
    {
        $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);

        $this->handler->expects($this->once())->method('gc')
            ->with(4711)->willReturn(1);

        $marshallingSessionHandler->gc(4711);
    }

    public function testRead()
    {
        $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);

        $this->handler->expects($this->once())->method('read')->with('session_id')
            ->willReturn('data');
        $this->marshaller->expects($this->once())->method('unmarshall')->with('data')
            ->willReturn('unmarshalled_data')
        ;

        
$this->currentHandler->expects($this->once())
            ->method('gc')
            ->with($maxlifetime)
            ->willReturn(1);

        $this->writeOnlyHandler->expects($this->once())
            ->method('gc')
            ->with($maxlifetime)
            ->willReturn(false);

        $this->assertSame(1, $this->dualHandler->gc($maxlifetime));
    }

    public function testOpen()
    {
        $savePath = '/path/to/save/location';
        $sessionName = 'xyz';

        $this->currentHandler->expects($this->once())
            ->method('open')
            ->with($savePath$sessionName)
            ->willReturn(true);

        
return $this->handler->destroy($sessionId);
    }

    public function close(): bool
    {
        return $this->handler->close();
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->handler->gc($maxlifetime);
    }
}
    {
        return $this->handler->write($sessionId$data);
    }

    public function destroy(#[\SensitiveParameter] string $sessionId): bool     {
        return $this->handler->destroy($sessionId);
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->handler->gc($maxlifetime);
    }

    public function validateId(#[\SensitiveParameter] string $sessionId): bool     {
        return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
    }

    public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId$data) : $this->write($sessionId$data);
    }
}
$this->assertTrue($this->proxy->destroy('id'));
    }

    public function testGc()
    {
        $this->mock->expects($this->once())
            ->method('gc')
            ->willReturn(1)
        ;

        $this->proxy->gc(86400);
    }

    public function testValidateId()
    {
        $mock = $this->createMock(TestSessionHandler::class);
        $mock->expects($this->once())
            ->method('validateId');

        $proxy = new SessionHandlerProxy($mock);
        $proxy->validateId('id');

        
public function destroy(#[\SensitiveParameter] string $sessionId): bool     {
        $result = $this->currentHandler->destroy($sessionId);
        $this->writeOnlyHandler->destroy($sessionId);

        return $result;
    }

    public function gc(int $maxlifetime): int|false
    {
        $result = $this->currentHandler->gc($maxlifetime);
        $this->writeOnlyHandler->gc($maxlifetime);

        return $result;
    }

    public function open(string $savePath, string $sessionName): bool
    {
        $result = $this->currentHandler->open($savePath$sessionName);
        $this->writeOnlyHandler->open($savePath$sessionName);

        return $result;
    }
$storage->close();

        $storage->open('', 'sid');
        $storage->read('gc_id');
        ini_set('session.gc_maxlifetime', -1); // test that you can set lifetime of a session after it has been read         $storage->write('gc_id', 'data');
        $storage->close();
        $this->assertEquals(2, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'No session pruned because gc not called');

        $storage->open('', 'sid');
        $data = $storage->read('gc_id');
        $storage->gc(-1);
        $storage->close();

        ini_set('session.gc_maxlifetime', $previousLifeTime);

        $this->assertSame('', $data, 'Session already considered garbage, so not returning data even if it is not pruned yet');
        $this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'Expired session is pruned');
    }

    public function testGetConnection()
    {
        $storage = new PdoSessionHandler($this->getMemorySqlitePdo());

        
public function destroy(#[\SensitiveParameter] string $sessionId): bool     {
        $result = $this->currentHandler->destroy($sessionId);
        $this->writeOnlyHandler->destroy($sessionId);

        return $result;
    }

    public function gc(int $maxlifetime): int|false
    {
        $result = $this->currentHandler->gc($maxlifetime);
        $this->writeOnlyHandler->gc($maxlifetime);

        return $result;
    }

    public function open(string $savePath, string $sessionName): bool
    {
        $result = $this->currentHandler->open($savePath$sessionName);
        $this->writeOnlyHandler->open($savePath$sessionName);

        return $result;
    }

        return $this->handler->close();
    }

    public function destroy(#[\SensitiveParameter] string $sessionId): bool     {
        return $this->handler->destroy($sessionId);
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->handler->gc($maxlifetime);
    }

    public function read(#[\SensitiveParameter] string $sessionId): string     {
        return $this->marshaller->unmarshall($this->handler->read($sessionId));
    }

    public function write(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        $failed = [];
        $marshalledData = $this->marshaller->marshall(['data' => $data]$failed);

        
return $this->handler->destroy($sessionId);
    }

    public function close(): bool
    {
        return $this->handler->close();
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->handler->gc($maxlifetime);
    }
}
Home | Imprint | This part of the site doesn't use cookies.