This commit is contained in:
@ -16,8 +16,8 @@ final class DbInitTest extends QdbTestCase
|
||||
qdb_discard($t1, $l1);
|
||||
|
||||
[$pdo2, $t2, $l2] = qdb_open(true);
|
||||
$pdo2->exec("INSERT INTO language (languageCode, name) VALUES ('fr', 'French')
|
||||
ON CONFLICT(languageCode) DO NOTHING");
|
||||
$pdo2->exec("INSERT INTO language (languageCode, name) VALUES ('fr', 'French') "
|
||||
. qdb_upsert_do_nothing(['languageCode']));
|
||||
qdb_save($t2, $l2);
|
||||
|
||||
[$pdo3, $t3, $l3] = qdb_open(false);
|
||||
@ -35,6 +35,26 @@ final class DbInitTest extends QdbTestCase
|
||||
qdb_discard($tmp, $lock);
|
||||
}
|
||||
|
||||
public function testSchemaSqlContentIsExecutedDirectly(): void
|
||||
{
|
||||
$pdo = new \PDO('sqlite::memory:');
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
qdb_exec_schema_sql($pdo, 'CREATE TABLE schema_sql_test (id INTEGER PRIMARY KEY);');
|
||||
|
||||
$this->assertTrue(qdb_table_exists($pdo, 'schema_sql_test'));
|
||||
}
|
||||
|
||||
public function testRuntimeDriverOverrideWinsOverConfiguration(): void
|
||||
{
|
||||
qdb_env_override('QDB_DRIVER', 'mysql');
|
||||
$this->assertSame('mysql', qdb_env_get('QDB_DRIVER'));
|
||||
$this->assertTrue(qdb_is_mysql());
|
||||
|
||||
qdb_env_override('QDB_DRIVER', 'sqlite');
|
||||
$this->assertTrue(qdb_is_sqlite());
|
||||
}
|
||||
|
||||
public function testMigrationsRecreateDroppedSubmissionTables(): void
|
||||
{
|
||||
[$pdo, $tmp, $lock] = qdb_open(true);
|
||||
|
||||
@ -22,8 +22,9 @@ require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__) . '/lib/response.php';
|
||||
require_once dirname(__DIR__) . '/common.php';
|
||||
|
||||
qdb_env_override('QDB_DRIVER', 'sqlite');
|
||||
|
||||
// Always use the test key, even when .env defines QDB_MASTER_KEY (avoids decrypt/seed drift).
|
||||
qdb_env_set('QDB_MASTER_KEY', $testMasterKey);
|
||||
$GLOBALS['qdb_dotenv']['QDB_MASTER_KEY'] = $testMasterKey;
|
||||
qdb_env_override('QDB_MASTER_KEY', $testMasterKey);
|
||||
|
||||
require_once dirname(__DIR__) . '/db_init.php';
|
||||
|
||||
40
tests/mysql_smoke.php
Normal file
40
tests/mysql_smoke.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__) . '/lib/response.php';
|
||||
require_once dirname(__DIR__) . '/common.php';
|
||||
|
||||
qdb_env_override('QDB_DRIVER', 'mysql');
|
||||
require_once dirname(__DIR__) . '/db_init.php';
|
||||
|
||||
[$pdo] = qdb_open(true);
|
||||
|
||||
foreach (['users', 'questionnaire', 'questionnaire_submission', 'system_setting'] as $table) {
|
||||
if (!qdb_table_exists($pdo, $table)) {
|
||||
throw new RuntimeException("MySQL smoke test: missing table {$table}");
|
||||
}
|
||||
}
|
||||
|
||||
if (qdb_schema_version($pdo) !== QDB_VERSION) {
|
||||
throw new RuntimeException('MySQL smoke test: incorrect schema version');
|
||||
}
|
||||
|
||||
// Schema application must be safe to retry after an interrupted or concurrent bootstrap.
|
||||
qdb_exec_schema_file($pdo, qdb_schema_file());
|
||||
|
||||
$pdo->exec("DELETE FROM language WHERE languageCode = 'ci-smoke'");
|
||||
$upsert = $pdo->prepare(
|
||||
'INSERT INTO language (languageCode, name, enabled) VALUES (:code, :name, 1) '
|
||||
. qdb_upsert_update(['languageCode'], ['name' => 'excluded.name'])
|
||||
);
|
||||
$upsert->execute([':code' => 'ci-smoke', ':name' => 'First']);
|
||||
$upsert->execute([':code' => 'ci-smoke', ':name' => 'Updated']);
|
||||
$name = $pdo->query("SELECT name FROM language WHERE languageCode = 'ci-smoke'")->fetchColumn();
|
||||
if ($name !== 'Updated') {
|
||||
throw new RuntimeException('MySQL smoke test: upsert failed');
|
||||
}
|
||||
$pdo->exec("DELETE FROM language WHERE languageCode = 'ci-smoke'");
|
||||
|
||||
fwrite(STDOUT, "MySQL smoke test passed\n");
|
||||
Reference in New Issue
Block a user