You are here

public function PdoSessionHandlerTest::testSessionGC in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php \Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\PdoSessionHandlerTest::testSessionGC()

File

vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php, line 265

Class

PdoSessionHandlerTest

Namespace

Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler

Code

public function testSessionGC() {
  $previousLifeTime = ini_set('session.gc_maxlifetime', 1000);
  $pdo = $this
    ->getMemorySqlitePdo();
  $storage = new PdoSessionHandler($pdo);
  $storage
    ->open('', 'sid');
  $storage
    ->read('id');
  $storage
    ->write('id', 'data');
  $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');
}