diff --git a/src/Sql/Ddl/AlterTableDecorator.php b/src/Sql/Ddl/AlterTableDecorator.php deleted file mode 100644 index 3b8d273..0000000 --- a/src/Sql/Ddl/AlterTableDecorator.php +++ /dev/null @@ -1,238 +0,0 @@ - 0, - 'zerofill' => 1, - 'identity' => 2, - 'serial' => 2, - 'autoincrement' => 2, - 'comment' => 3, - 'columnformat' => 4, - 'format' => 4, - 'storage' => 5, - 'after' => 6, - ]; - - /** - * @param AlterTable $subject - * @return $this Provides a fluent interface - */ - public function setSubject($subject): static - { - $this->subject = $subject; - - return $this; - } - - /** - * @return array - */ - protected function getSqlInsertOffsets(string $sql): array - { - $sqlLength = strlen($sql); - $insertStart = []; - - foreach (['NOT NULL', 'NULL', 'DEFAULT', 'UNIQUE', 'PRIMARY', 'REFERENCES'] as $needle) { - $insertPos = strpos($sql, ' ' . $needle); - - if ($insertPos !== false) { - switch ($needle) { - case 'REFERENCES': - $insertStart[2] = ! isset($insertStart[2]) ? $insertPos : $insertStart[2]; - // no break - case 'PRIMARY': - case 'UNIQUE': - $insertStart[1] = ! isset($insertStart[1]) ? $insertPos : $insertStart[1]; - // no break - default: - $insertStart[0] = ! isset($insertStart[0]) ? $insertPos : $insertStart[0]; - } - } - } - - foreach (range(0, 3) as $i) { - $insertStart[$i] = $insertStart[$i] ?? $sqlLength; - } - - return $insertStart; - } - - protected function processAddColumns(?PlatformInterface $adapterPlatform = null): array - { - $sqls = []; - - foreach ($this->addColumns as $i => $column) { - $sql = $this->processExpression($column, $adapterPlatform); - $insertStart = $this->getSqlInsertOffsets($sql); - $columnOptions = $column->getOptions(); - - uksort($columnOptions, [$this, 'compareColumnOptions']); - - foreach ($columnOptions as $coName => $coValue) { - $insert = ''; - - if (! $coValue) { - continue; - } - - switch ($this->normalizeColumnOption($coName)) { - case 'unsigned': - $insert = ' UNSIGNED'; - $j = 0; - break; - case 'zerofill': - $insert = ' ZEROFILL'; - $j = 0; - break; - case 'identity': - case 'serial': - case 'autoincrement': - $insert = ' AUTO_INCREMENT'; - $j = 1; - break; - case 'comment': - $insert = ' COMMENT ' . $adapterPlatform->quoteValue($coValue); - $j = 2; - break; - case 'columnformat': - case 'format': - $insert = ' COLUMN_FORMAT ' . strtoupper($coValue); - $j = 2; - break; - case 'storage': - $insert = ' STORAGE ' . strtoupper($coValue); - $j = 2; - break; - case 'after': - $insert = ' AFTER ' . $adapterPlatform->quoteIdentifier($coValue); - $j = 2; - } - - if ($insert) { - $j = $j ?? 0; - $sql = substr_replace($sql, $insert, $insertStart[$j], 0); - $insertStartCount = count($insertStart); - for (; $j < $insertStartCount; ++$j) { - $insertStart[$j] += strlen($insert); - } - } - } - $sqls[$i] = $sql; - } - return [$sqls]; - } - - protected function processChangeColumns(?PlatformInterface $adapterPlatform = null): array - { - $sqls = []; - - /** @var ColumnInterface $column */ - foreach ($this->changeColumns as $name => $column) { - $sql = $this->processExpression($column, $adapterPlatform); - $insertStart = $this->getSqlInsertOffsets($sql); - $columnOptions = $column->getOptions(); - - uksort($columnOptions, [$this, 'compareColumnOptions']); - - foreach ($columnOptions as $coName => $coValue) { - $insert = ''; - - if (! $coValue) { - continue; - } - - switch ($this->normalizeColumnOption($coName)) { - case 'unsigned': - $insert = ' UNSIGNED'; - $j = 0; - break; - case 'zerofill': - $insert = ' ZEROFILL'; - $j = 0; - break; - case 'identity': - case 'serial': - case 'autoincrement': - $insert = ' AUTO_INCREMENT'; - $j = 1; - break; - case 'comment': - $insert = ' COMMENT ' . $adapterPlatform->quoteValue($coValue); - $j = 2; - break; - case 'columnformat': - case 'format': - $insert = ' COLUMN_FORMAT ' . strtoupper($coValue); - $j = 2; - break; - case 'storage': - $insert = ' STORAGE ' . strtoupper($coValue); - $j = 2; - break; - } - - if ($insert) { - $j = $j ?? 0; - $sql = substr_replace($sql, $insert, $insertStart[$j], 0); - $insertStartCount = count($insertStart); - for (; $j < $insertStartCount; ++$j) { - $insertStart[$j] += strlen($insert); - } - } - } - $sqls[] = [ - $adapterPlatform->quoteIdentifier($name), - $sql, - ]; - } - - return [$sqls]; - } - - private function normalizeColumnOption(string $name): string - { - return strtolower(str_replace(['-', '_', ' '], '', $name)); - } - - /** - * phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod - * - * @psalm-suppress UnusedReturnValue - */ - private function compareColumnOptions(string $columnA, string $columnB): int - { - $columnA = $this->normalizeColumnOption($columnA); - $columnA = $this->columnOptionSortOrder[$columnA] ?? count($this->columnOptionSortOrder); - - $columnB = $this->normalizeColumnOption($columnB); - $columnB = $this->columnOptionSortOrder[$columnB] ?? count($this->columnOptionSortOrder); - - return $columnA - $columnB; - } -} diff --git a/src/Sql/Ddl/CreateTableDecorator.php b/src/Sql/Ddl/CreateTableDecorator.php deleted file mode 100644 index ee4824f..0000000 --- a/src/Sql/Ddl/CreateTableDecorator.php +++ /dev/null @@ -1,176 +0,0 @@ - 0, - 'zerofill' => 1, - 'identity' => 2, - 'serial' => 2, - 'autoincrement' => 2, - 'comment' => 3, - 'columnformat' => 4, - 'format' => 4, - 'storage' => 5, - ]; - - /** - * @param CreateTable $subject - * @return $this Provides a fluent interface - */ - public function setSubject($subject): static - { - $this->subject = $subject; - - return $this; - } - - /** - * @return array - */ - protected function getSqlInsertOffsets(string $sql): array - { - $sqlLength = strlen($sql); - $insertStart = []; - - foreach (['NOT NULL', 'NULL', 'DEFAULT', 'UNIQUE', 'PRIMARY', 'REFERENCES'] as $needle) { - $insertPos = strpos($sql, ' ' . $needle); - - if ($insertPos !== false) { - switch ($needle) { - case 'REFERENCES': - $insertStart[2] = ! isset($insertStart[2]) ? $insertPos : $insertStart[2]; - // no break - case 'PRIMARY': - case 'UNIQUE': - $insertStart[1] = ! isset($insertStart[1]) ? $insertPos : $insertStart[1]; - // no break - default: - $insertStart[0] = ! isset($insertStart[0]) ? $insertPos : $insertStart[0]; - } - } - } - - foreach (range(0, 3) as $i) { - $insertStart[$i] = $insertStart[$i] ?? $sqlLength; - } - - return $insertStart; - } - - /** - * {@inheritDoc} - */ - protected function processColumns(PlatformInterface|null $adapterPlatform = null): ?array - { - if (! $this->columns) { - return null; - } - - $sqls = []; - - foreach ($this->columns as $i => $column) { - $sql = $this->processExpression($column, $adapterPlatform); - $insertStart = $this->getSqlInsertOffsets($sql); - $columnOptions = $column->getOptions(); - - uksort($columnOptions, [$this, 'compareColumnOptions']); - - foreach ($columnOptions as $coName => $coValue) { - $insert = ''; - - if (! $coValue) { - continue; - } - - switch ($this->normalizeColumnOption($coName)) { - case 'unsigned': - $insert = ' UNSIGNED'; - $j = 0; - break; - case 'zerofill': - $insert = ' ZEROFILL'; - $j = 0; - break; - case 'identity': - case 'serial': - case 'autoincrement': - $insert = ' AUTO_INCREMENT'; - $j = 1; - break; - case 'comment': - $insert = ' COMMENT ' . $adapterPlatform->quoteValue($coValue); - $j = 2; - break; - case 'columnformat': - case 'format': - $insert = ' COLUMN_FORMAT ' . strtoupper($coValue); - $j = 2; - break; - case 'storage': - $insert = ' STORAGE ' . strtoupper($coValue); - $j = 2; - break; - } - - if ($insert) { - $j = $j ?? 0; - $sql = substr_replace($sql, $insert, $insertStart[$j], 0); - $insertStartCount = count($insertStart); - for (; $j < $insertStartCount; ++$j) { - $insertStart[$j] += strlen($insert); - } - } - } - - $sqls[$i] = $sql; - } - - return [$sqls]; - } - - private function normalizeColumnOption(string $name): string - { - return strtolower(str_replace(['-', '_', ' '], '', $name)); - } - - /** - * phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod - * - * @psalm-suppress UnusedReturnValue - */ - private function compareColumnOptions(string $columnA, string $columnB): int - { - $columnA = $this->normalizeColumnOption($columnA); - $columnA = $this->columnOptionSortOrder[$columnA] ?? count($this->columnOptionSortOrder); - - $columnB = $this->normalizeColumnOption($columnB); - $columnB = $this->columnOptionSortOrder[$columnB] ?? count($this->columnOptionSortOrder); - - return $columnA - $columnB; - } -} diff --git a/src/Sql/Platform.php b/src/Sql/Platform.php index e6c5c79..547f16c 100644 --- a/src/Sql/Platform.php +++ b/src/Sql/Platform.php @@ -4,8 +4,6 @@ namespace PhpDb\Sqlite\Sql; -use PhpDb\Sql\Ddl\AlterTable; -use PhpDb\Sql\Ddl\CreateTable; use PhpDb\Sql\Platform\AbstractPlatform; use PhpDb\Sql\Select; @@ -14,7 +12,5 @@ final class Platform extends AbstractPlatform public function __construct() { $this->setTypeDecorator(Select::class, new SelectDecorator()); - $this->setTypeDecorator(CreateTable::class, new Ddl\CreateTableDecorator()); - $this->setTypeDecorator(AlterTable::class, new Ddl\AlterTableDecorator()); } } diff --git a/test/unit/Sql/Ddl/AlterTableDecoratorTest.php b/test/unit/Sql/Ddl/AlterTableDecoratorTest.php deleted file mode 100644 index ea706be..0000000 --- a/test/unit/Sql/Ddl/AlterTableDecoratorTest.php +++ /dev/null @@ -1,252 +0,0 @@ -decorator = new AlterTableDecorator(); - } - - public function testSetSubject(): void - { - $alterTable = new AlterTable('test_table'); - $result = $this->decorator->setSubject($alterTable); - - self::assertSame($this->decorator, $result); - - $reflection = new ReflectionClass($this->decorator); - $subjectProperty = $reflection->getProperty('subject'); - $subject = $subjectProperty->getValue($this->decorator); - - self::assertSame($alterTable, $subject); - } - - public function testColumnOptionSortOrder(): void - { - $reflection = new ReflectionClass($this->decorator); - $sortOrderProperty = $reflection->getProperty('columnOptionSortOrder'); - $sortOrder = $sortOrderProperty->getValue($this->decorator); - - self::assertIsArray($sortOrder); - self::assertArrayHasKey('unsigned', $sortOrder); - self::assertArrayHasKey('zerofill', $sortOrder); - self::assertArrayHasKey('identity', $sortOrder); - self::assertArrayHasKey('serial', $sortOrder); - self::assertArrayHasKey('autoincrement', $sortOrder); - self::assertArrayHasKey('comment', $sortOrder); - self::assertArrayHasKey('columnformat', $sortOrder); - self::assertArrayHasKey('format', $sortOrder); - self::assertArrayHasKey('storage', $sortOrder); - self::assertArrayHasKey('after', $sortOrder); - } - - public function testColumnOptionSortOrderIncludesAfter(): void - { - $reflection = new ReflectionClass($this->decorator); - $sortOrderProperty = $reflection->getProperty('columnOptionSortOrder'); - $sortOrder = $sortOrderProperty->getValue($this->decorator); - - self::assertArrayHasKey('after', $sortOrder); - self::assertSame(6, $sortOrder['after']); - } - - public function testGetSqlInsertOffsets(): void - { - $sql = 'column_name VARCHAR(255) NOT NULL DEFAULT "test" UNIQUE PRIMARY REFERENCES other_table(id)'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertCount(4, $offsets); - self::assertIsInt($offsets[0]); - self::assertIsInt($offsets[1]); - self::assertIsInt($offsets[2]); - self::assertIsInt($offsets[3]); - } - - public function testGetSqlInsertOffsetsWithNullKeyword(): void - { - $sql = 'column_name VARCHAR(255) NULL'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[0]); - } - - public function testGetSqlInsertOffsetsWithDefaultKeyword(): void - { - $sql = 'column_name INTEGER DEFAULT 42'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[0]); - } - - public function testGetSqlInsertOffsetsWithUniqueKeyword(): void - { - $sql = 'column_name VARCHAR(100) UNIQUE'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[1]); - } - - public function testGetSqlInsertOffsetsWithPrimaryKeyword(): void - { - $sql = 'id INTEGER PRIMARY KEY'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[1]); - } - - public function testGetSqlInsertOffsetsWithReferencesKeyword(): void - { - $sql = 'user_id INTEGER REFERENCES users(id)'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[2]); - } - - public function testGetSqlInsertOffsetsWithoutKeywords(): void - { - $sql = 'column_name VARCHAR(255)'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - $sqlLength = strlen($sql); - self::assertSame($sqlLength, $offsets[0]); - self::assertSame($sqlLength, $offsets[1]); - self::assertSame($sqlLength, $offsets[2]); - self::assertSame($sqlLength, $offsets[3]); - } - - public function testNormalizeColumnOption(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('normalizeColumnOption'); - - self::assertSame('autoincrement', $method->invoke($this->decorator, 'auto-increment')); - self::assertSame('autoincrement', $method->invoke($this->decorator, 'auto_increment')); - self::assertSame('autoincrement', $method->invoke($this->decorator, 'AUTO INCREMENT')); - self::assertSame('columnformat', $method->invoke($this->decorator, 'column-format')); - self::assertSame('zerofill', $method->invoke($this->decorator, 'ZERO_FILL')); - self::assertSame('after', $method->invoke($this->decorator, 'AFTER')); - } - - public function testCompareColumnOptions(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // unsigned (0) should come before zerofill (1) - $result = $method->invoke($this->decorator, 'unsigned', 'zerofill'); - self::assertLessThan(0, $result); - - // zerofill (1) should come before identity (2) - $result = $method->invoke($this->decorator, 'zerofill', 'identity'); - self::assertLessThan(0, $result); - - // identity (2) should come before comment (3) - $result = $method->invoke($this->decorator, 'identity', 'comment'); - self::assertLessThan(0, $result); - - // comment (3) should come before columnformat (4) - $result = $method->invoke($this->decorator, 'comment', 'columnformat'); - self::assertLessThan(0, $result); - - // storage (5) should come before after (6) - $result = $method->invoke($this->decorator, 'storage', 'after'); - self::assertLessThan(0, $result); - } - - public function testCompareColumnOptionsWithSameValue(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - $result = $method->invoke($this->decorator, 'unsigned', 'unsigned'); - self::assertSame(0, $result); - } - - public function testCompareColumnOptionsWithUnknownOptions(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // Unknown options should be treated equally - $result = $method->invoke($this->decorator, 'unknown1', 'unknown2'); - self::assertSame(0, $result); - } - - public function testCompareColumnOptionsKnownVsUnknown(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // Known option should come before unknown option - $result = $method->invoke($this->decorator, 'unsigned', 'unknown'); - self::assertLessThan(0, $result); - - // Unknown option should come after known option - $result = $method->invoke($this->decorator, 'unknown', 'unsigned'); - self::assertGreaterThan(0, $result); - } - - public function testCompareColumnOptionsAfterIsLast(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // 'after' should come after 'storage' - $result = $method->invoke($this->decorator, 'storage', 'after'); - self::assertLessThan(0, $result); - - // 'after' should come after 'comment' - $result = $method->invoke($this->decorator, 'comment', 'after'); - self::assertLessThan(0, $result); - } -} diff --git a/test/unit/Sql/Ddl/CreateTableDecoratorTest.php b/test/unit/Sql/Ddl/CreateTableDecoratorTest.php deleted file mode 100644 index 76c12a0..0000000 --- a/test/unit/Sql/Ddl/CreateTableDecoratorTest.php +++ /dev/null @@ -1,226 +0,0 @@ -decorator = new CreateTableDecorator(); - } - - public function testSetSubject(): void - { - $createTable = new CreateTable('test_table'); - $result = $this->decorator->setSubject($createTable); - - self::assertSame($this->decorator, $result); - - $reflection = new ReflectionClass($this->decorator); - $subjectProperty = $reflection->getProperty('subject'); - $subject = $subjectProperty->getValue($this->decorator); - - self::assertSame($createTable, $subject); - } - - public function testColumnOptionSortOrder(): void - { - $reflection = new ReflectionClass($this->decorator); - $sortOrderProperty = $reflection->getProperty('columnOptionSortOrder'); - $sortOrder = $sortOrderProperty->getValue($this->decorator); - - self::assertIsArray($sortOrder); - self::assertArrayHasKey('unsigned', $sortOrder); - self::assertArrayHasKey('zerofill', $sortOrder); - self::assertArrayHasKey('identity', $sortOrder); - self::assertArrayHasKey('serial', $sortOrder); - self::assertArrayHasKey('autoincrement', $sortOrder); - self::assertArrayHasKey('comment', $sortOrder); - self::assertArrayHasKey('columnformat', $sortOrder); - self::assertArrayHasKey('format', $sortOrder); - self::assertArrayHasKey('storage', $sortOrder); - } - - public function testGetSqlInsertOffsets(): void - { - $sql = 'column_name VARCHAR(255) NOT NULL DEFAULT "test" UNIQUE PRIMARY REFERENCES other_table(id)'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertCount(4, $offsets); - self::assertIsInt($offsets[0]); - self::assertIsInt($offsets[1]); - self::assertIsInt($offsets[2]); - self::assertIsInt($offsets[3]); - } - - public function testGetSqlInsertOffsetsWithNullKeyword(): void - { - $sql = 'column_name VARCHAR(255) NULL'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[0]); - } - - public function testGetSqlInsertOffsetsWithDefaultKeyword(): void - { - $sql = 'column_name INTEGER DEFAULT 42'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[0]); - } - - public function testGetSqlInsertOffsetsWithUniqueKeyword(): void - { - $sql = 'column_name VARCHAR(100) UNIQUE'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[1]); - } - - public function testGetSqlInsertOffsetsWithPrimaryKeyword(): void - { - $sql = 'id INTEGER PRIMARY KEY'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[1]); - } - - public function testGetSqlInsertOffsetsWithReferencesKeyword(): void - { - $sql = 'user_id INTEGER REFERENCES users(id)'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - self::assertGreaterThan(0, $offsets[2]); - } - - public function testGetSqlInsertOffsetsWithoutKeywords(): void - { - $sql = 'column_name VARCHAR(255)'; - - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('getSqlInsertOffsets'); - - $offsets = $method->invoke($this->decorator, $sql); - - self::assertIsArray($offsets); - $sqlLength = strlen($sql); - self::assertSame($sqlLength, $offsets[0]); - self::assertSame($sqlLength, $offsets[1]); - self::assertSame($sqlLength, $offsets[2]); - self::assertSame($sqlLength, $offsets[3]); - } - - public function testNormalizeColumnOption(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('normalizeColumnOption'); - - self::assertSame('autoincrement', $method->invoke($this->decorator, 'auto-increment')); - self::assertSame('autoincrement', $method->invoke($this->decorator, 'auto_increment')); - self::assertSame('autoincrement', $method->invoke($this->decorator, 'AUTO INCREMENT')); - self::assertSame('columnformat', $method->invoke($this->decorator, 'column-format')); - self::assertSame('zerofill', $method->invoke($this->decorator, 'ZERO_FILL')); - } - - public function testCompareColumnOptions(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // unsigned (0) should come before zerofill (1) - $result = $method->invoke($this->decorator, 'unsigned', 'zerofill'); - self::assertLessThan(0, $result); - - // zerofill (1) should come before identity (2) - $result = $method->invoke($this->decorator, 'zerofill', 'identity'); - self::assertLessThan(0, $result); - - // identity (2) should come before comment (3) - $result = $method->invoke($this->decorator, 'identity', 'comment'); - self::assertLessThan(0, $result); - - // comment (3) should come before columnformat (4) - $result = $method->invoke($this->decorator, 'comment', 'columnformat'); - self::assertLessThan(0, $result); - - // storage (5) should come after format (4) - $result = $method->invoke($this->decorator, 'format', 'storage'); - self::assertLessThan(0, $result); - } - - public function testCompareColumnOptionsWithSameValue(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - $result = $method->invoke($this->decorator, 'unsigned', 'unsigned'); - self::assertSame(0, $result); - } - - public function testCompareColumnOptionsWithUnknownOptions(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // Unknown options should be treated equally - $result = $method->invoke($this->decorator, 'unknown1', 'unknown2'); - self::assertSame(0, $result); - } - - public function testCompareColumnOptionsKnownVsUnknown(): void - { - $reflection = new ReflectionClass($this->decorator); - $method = $reflection->getMethod('compareColumnOptions'); - - // Known option should come before unknown option - $result = $method->invoke($this->decorator, 'unsigned', 'unknown'); - self::assertLessThan(0, $result); - - // Unknown option should come after known option - $result = $method->invoke($this->decorator, 'unknown', 'unsigned'); - self::assertGreaterThan(0, $result); - } -} diff --git a/test/unit/Sql/PlatformTest.php b/test/unit/Sql/PlatformTest.php index 756f612..2e1a2f0 100644 --- a/test/unit/Sql/PlatformTest.php +++ b/test/unit/Sql/PlatformTest.php @@ -4,11 +4,7 @@ namespace PhpDbTest\Sqlite\Sql; -use PhpDb\Sql\Ddl\AlterTable; -use PhpDb\Sql\Ddl\CreateTable; use PhpDb\Sql\Select; -use PhpDb\Sqlite\Sql\Ddl\AlterTableDecorator; -use PhpDb\Sqlite\Sql\Ddl\CreateTableDecorator; use PhpDb\Sqlite\Sql\Platform; use PhpDb\Sqlite\Sql\SelectDecorator; use PHPUnit\Framework\Attributes\CoversClass; @@ -39,24 +35,4 @@ public function testSelectDecoratorIsRegistered(): void self::assertArrayHasKey(Select::class, $decorators); self::assertInstanceOf(SelectDecorator::class, $decorators[Select::class]); } - - public function testCreateTableDecoratorIsRegistered(): void - { - $reflection = new ReflectionClass($this->platform); - $decoratorsProperty = $reflection->getProperty('decorators'); - $decorators = $decoratorsProperty->getValue($this->platform); - - self::assertArrayHasKey(CreateTable::class, $decorators); - self::assertInstanceOf(CreateTableDecorator::class, $decorators[CreateTable::class]); - } - - public function testAlterTableDecoratorIsRegistered(): void - { - $reflection = new ReflectionClass($this->platform); - $decoratorsProperty = $reflection->getProperty('decorators'); - $decorators = $decoratorsProperty->getValue($this->platform); - - self::assertArrayHasKey(AlterTable::class, $decorators); - self::assertInstanceOf(AlterTableDecorator::class, $decorators[AlterTable::class]); - } }