37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
<?php
|
|
namespace nur\sery\db\sqlite;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SqliteTest extends TestCase {
|
|
const CREATE_PERSON = "create table person(nom varchar, prenom varchar, age integer)";
|
|
const INSERT_JEPHTE = "insert into person(nom, prenom, age) values ('clain', 'jephte', 50)";
|
|
const INSERT_JEAN = "insert into person(nom, prenom, age) values ('payet', 'jean', 32)";
|
|
|
|
function testMigration() {
|
|
$sqlite = new Sqlite(":memory:", [
|
|
"migrate" => [
|
|
self::CREATE_PERSON,
|
|
self::INSERT_JEPHTE,
|
|
],
|
|
]);
|
|
self::assertSame("clain", $sqlite->get("select nom, age from person"));
|
|
self::assertSame([
|
|
"nom" => "clain",
|
|
"age" => 50,
|
|
], $sqlite->get("select nom, age from person", null, true));
|
|
|
|
$sqlite->exec(self::INSERT_JEAN);
|
|
self::assertSame("payet", $sqlite->get("select nom, age from person where nom = 'payet'"));
|
|
self::assertSame([
|
|
"nom" => "payet",
|
|
"age" => 32,
|
|
], $sqlite->get("select nom, age from person where nom = 'payet'", null, true));
|
|
|
|
self::assertSame([
|
|
["key" => "0", "value" => self::CREATE_PERSON, "done" => 1],
|
|
["key" => "1", "value" => self::INSERT_JEPHTE, "done" => 1],
|
|
], iterator_to_array($sqlite->all("select key, value, done from _migration")));
|
|
}
|
|
}
|