First cut of ID generation need detection
This commit is contained in:
@@ -87,64 +87,56 @@ class QueryTest extends TestCase
|
||||
#[TestDox('Insert succeeds with auto numeric ID for PostgreSQL')]
|
||||
public function testInsertSucceedsWithAutoNumericIdForPostgreSQL(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
try {
|
||||
$this->assertEquals(
|
||||
"INSERT INTO test_tbl VALUES (:data || ('{\"id\":' "
|
||||
. "|| (SELECT COALESCE(MAX(data->>'id'), 0) + 1 FROM test_tbl) || '}'))",
|
||||
Query::insert('test_tbl'), 'INSERT statement not constructed correctly');
|
||||
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
Configuration::$autoId = AutoId::None;
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto numeric ID for SQLite')]
|
||||
public function testInsertSucceedsWithAutoNumericIdForSQLite(): void
|
||||
{
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
try {
|
||||
$this->assertEquals(
|
||||
"INSERT INTO test_tbl VALUES (json_set(:data, '$.id', "
|
||||
. "(SELECT coalesce(max(data->>'id'), 0) + 1 FROM test_tbl)))",
|
||||
Query::insert('test_tbl'), 'INSERT statement not constructed correctly');
|
||||
Query::insert('test_tbl', AutoId::Number), 'INSERT statement not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
Configuration::$autoId = AutoId::None;
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto UUID for PostgreSQL')]
|
||||
public function testInsertSucceedsWithAutoUuidForPostgreSQL(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
try {
|
||||
$query = Query::insert('test_tbl');
|
||||
$query = Query::insert('test_tbl', AutoId::UUID);
|
||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (:data || '{\"id\":\"", $query,
|
||||
'INSERT statement not constructed correctly');
|
||||
$this->assertStringEndsWith("\"}')", $query, 'INSERT statement not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
Configuration::$autoId = AutoId::None;
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#[TestDox('Insert succeeds with auto UUID for SQLite')]
|
||||
public function testInsertSucceedsWithAutoUuidForSQLite(): void
|
||||
{
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
Configuration::$autoId = AutoId::UUID;
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
try {
|
||||
$query = Query::insert('test_tbl');
|
||||
$query = Query::insert('test_tbl', AutoId::UUID);
|
||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query,
|
||||
'INSERT statement not constructed correctly');
|
||||
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
Configuration::$autoId = AutoId::None;
|
||||
Configuration::$mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,10 +144,9 @@ class QueryTest extends TestCase
|
||||
public function testInsertSucceedsWithAutoRandomStringForPostgreSQL(): void
|
||||
{
|
||||
Configuration::$mode = Mode::PgSQL;
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
Configuration::$idStringLength = 8;
|
||||
try {
|
||||
$query = Query::insert('test_tbl');
|
||||
$query = Query::insert('test_tbl', AutoId::RandomString);
|
||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (:data || '{\"id\":\"", $query,
|
||||
'INSERT statement not constructed correctly');
|
||||
$this->assertStringEndsWith("\"}')", $query, 'INSERT statement not constructed correctly');
|
||||
@@ -163,7 +154,6 @@ class QueryTest extends TestCase
|
||||
$this->assertEquals(8, strlen($id), "Generated ID [$id] should have been 8 characters long");
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
Configuration::$autoId = AutoId::None;
|
||||
Configuration::$idStringLength = 16;
|
||||
}
|
||||
}
|
||||
@@ -172,9 +162,8 @@ class QueryTest extends TestCase
|
||||
public function testInsertSucceedsWithAutoRandomStringForSQLite(): void
|
||||
{
|
||||
Configuration::$mode = Mode::SQLite;
|
||||
Configuration::$autoId = AutoId::RandomString;
|
||||
try {
|
||||
$query = Query::insert('test_tbl');
|
||||
$query = Query::insert('test_tbl', AutoId::RandomString);
|
||||
$this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query,
|
||||
'INSERT statement not constructed correctly');
|
||||
$this->assertStringEndsWith("'))", $query, 'INSERT statement not constructed correctly');
|
||||
@@ -182,7 +171,6 @@ class QueryTest extends TestCase
|
||||
$this->assertEquals(16, strlen($id), "Generated ID [$id] should have been 16 characters long");
|
||||
} finally {
|
||||
Configuration::$mode = null;
|
||||
Configuration::$autoId = AutoId::None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user