Add mode, bring in definition/patch queries

This commit is contained in:
2024-06-03 21:09:03 -04:00
parent ecc13a30cf
commit 98bfceb7c9
10 changed files with 219 additions and 7 deletions

View File

@@ -2,7 +2,11 @@
namespace Test\Unit\Query;
use BitBadger\PDODocument\Configuration;
use BitBadger\PDODocument\DocumentException;
use BitBadger\PDODocument\Mode;
use BitBadger\PDODocument\Query\Definition;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
/**
@@ -10,10 +14,35 @@ use PHPUnit\Framework\TestCase;
*/
class DefinitionTest extends TestCase
{
public function testEnsureTableForSucceeds(): void
#[TestDox('Ensure table succeeds for PosgtreSQL')]
public function testEnsureTableSucceedsForPostgreSQL(): void
{
$this->assertEquals('CREATE TABLE IF NOT EXISTS documents (data JSON NOT NULL)',
Definition::ensureTableFor('documents', 'JSON'), 'CREATE TABLE statement not generated correctly');
try {
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('CREATE TABLE IF NOT EXISTS documents (data JSONB NOT NULL)',
Definition::ensureTable('documents'), 'CREATE TABLE statement not generated correctly');
} finally {
Configuration::$mode = null;
}
}
#[TestDox('Ensure table succeeds for SQLite')]
public function testEnsureTableSucceedsForSQLite(): void
{
try {
Configuration::$mode = Mode::SQLite;
$this->assertEquals('CREATE TABLE IF NOT EXISTS dox (data TEXT NOT NULL)', Definition::ensureTable('dox'),
'CREATE TABLE statement not generated correctly');
} finally {
Configuration::$mode = null;
}
}
public function testEnsureTableFailsWhenModeNotSet(): void
{
$this->expectException(DocumentException::class);
Configuration::$mode = null;
Definition::ensureTable('boom');
}
public function testEnsureIndexOnSucceedsWithoutSchemaSingleAscendingField(): void