Пример #1
0
 /**
  * Test the rand function
  */
 public function testRand()
 {
     $pdo = new PDO("sqlite::memory:", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
     MySQLite::createFunctions($pdo);
     $pdo->exec("CREATE TABLE testing(id INT PRIMARY KEY NOT NULL)");
     $stmt = $pdo->prepare("INSERT INTO testing (id) VALUES (?)");
     for ($x = 0; $x <= 10; $x++) {
         $stmt->execute([$x]);
     }
     $results = [];
     for ($x = 0; $x < 20; $x++) {
         $results[] = $pdo->query('SELECT id FROM testing ORDER BY RAND() LIMIT 1')->fetch(PDO::FETCH_COLUMN);
     }
     $this->assertNotEquals(array_slice($results, 0, 10), array_slice($results, 10, 10));
 }