Add classes and tests from common project

This commit is contained in:
2024-06-03 19:46:39 -04:00
parent e91acee70f
commit 1164dc7cc5
32 changed files with 3175 additions and 0 deletions

View 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');
}
}