/** * Session GC (garbage collection) handler. * Do not call this method directly. * @param integer $maxLifetime the number of seconds after which data will be seen as 'garbage' and cleaned up. * @return boolean whether session is GCed successfully */ public function gcSession($maxLifetime) { if ($this->dbSession) { return $this->dbSession->gcSession($maxLifetime); } else { parent::gcSession($maxLifetime); } }
/** * @depends testReadWrite */ public function testGarbageCollection() { $session = new DbSession(); $session->writeSession('new', 'new data'); $session->writeSession('expire', 'expire data'); $session->db->createCommand()->update('session', ['expire' => time() - 100], 'id = :id', ['id' => 'expire'])->execute(); $session->gcSession(1); $this->assertEquals('', $session->readSession('expire')); $this->assertEquals('new data', $session->readSession('new')); }