/** * @runInSeparateProcess */ public function testGc() { $MysqlAdapter = new MysqlPDOAdapter($GLOBALS['db_type'] . ':host=' . $GLOBALS['db_host'] . ';dbname=' . $GLOBALS['db_name'] . ';charset=utf8mb4', $GLOBALS['db_username'], $GLOBALS['db_password'], array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING)); $dbase = new Database($MysqlAdapter); $sessionHandler = new DatabaseSessionHandler($dbase); $conn = $dbase->connect(); $pdos = $conn->prepare('DELETE FROM session'); $pdos->execute(); for ($i = 0; $i < 10; $i++) { $sessionId = md5($i); $time = time() - $i; $data = 'time|i:' . $time . ';'; $pdos = $conn->prepare('INSERT INTO session (session_id, session_data) VALUES (:session_id, :session_data)'); $pdos->bindParam(':session_id', $sessionId, \PDO::PARAM_STR); $pdos->bindParam(':session_data', $data, \PDO::PARAM_STR); $pdos->execute(); } $sessionHandler->gc(-1); $pdos = $conn->prepare('SELECT * FROM session'); $pdos->execute(); $this->assertEquals(0, $pdos->rowCount()); }
/** * Constructor * */ public function __construct(Database $dBase, Password $password) { $this->dBase = $dBase->connect(); $this->password = $password; }
public function testConnection() { $MysqlAdapter = new MysqlPDOAdapter($GLOBALS['db_type'] . ':host=' . $GLOBALS['db_host'] . ';dbname=' . $GLOBALS['db_name'] . ';charset=utf8mb4', $GLOBALS['db_username'], $GLOBALS['db_password'], array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING)); $dbase = new Database($MysqlAdapter); $this->assertInstanceOf(PDO::class, $dbase->connect()); }
/** * Constructor * * @param Database $storage Database object */ public function __construct(Database $storage) { $this->dBase = $storage->connect(); }