Add classes and tests from common project
This commit is contained in:
38
tests/unit/Query/DefinitionTest.php
Normal file
38
tests/unit/Query/DefinitionTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Test\Unit\Query;
|
||||
|
||||
use BitBadger\PDODocument\Query\Definition;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the Definition class
|
||||
*/
|
||||
class DefinitionTest extends TestCase
|
||||
{
|
||||
public function testEnsureTableForSucceeds(): void
|
||||
{
|
||||
$this->assertEquals('CREATE TABLE IF NOT EXISTS documents (data JSON NOT NULL)',
|
||||
Definition::ensureTableFor('documents', 'JSON'), 'CREATE TABLE statement not generated correctly');
|
||||
}
|
||||
|
||||
public function testEnsureIndexOnSucceedsWithoutSchemaSingleAscendingField(): void
|
||||
{
|
||||
$this->assertEquals("CREATE INDEX IF NOT EXISTS idx_test_fields ON test ((data->>'details'))",
|
||||
Definition::ensureIndexOn('test', 'fields', ['details']), 'CREATE INDEX statement not generated correctly');
|
||||
}
|
||||
|
||||
public function testEnsureIndexOnSucceedsWithSchemaMultipleFields(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
"CREATE INDEX IF NOT EXISTS idx_testing_json ON sch.testing ((data->>'group'), (data->>'sub_group') DESC)",
|
||||
Definition::ensureIndexOn('sch.testing', 'json', ['group', 'sub_group DESC']),
|
||||
'CREATE INDEX statement not generated correctly');
|
||||
}
|
||||
|
||||
public function testEnsureKey(): void
|
||||
{
|
||||
$this->assertEquals("CREATE UNIQUE INDEX IF NOT EXISTS idx_tbl_key ON tbl ((data->>'id'))",
|
||||
Definition::ensureKey('tbl'), 'CREATE INDEX statement for document key not generated correctly');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user