packages/sql-fixture/tests/Unit/Platform/MySql/Schema/TableDefinitionInputTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Platform\MySql\Schema;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use SqlFixture\Platform\MySql\Schema\TableDefinitionInput as Subject;
10
11#[CoversClass(Subject::class)]
12final class TableDefinitionInputTest extends TestCase
13{
14 public function testWithoutPartitioningKeepsColumnMetadataBeforeAsValues(): void
15 {
16 $sql = 'CREATE TABLE t (value VARBINARY(1)) STATS_SAMPLE_PAGES 1 PARTITION BY KEY () REPLACE AS VALUES ROW (NULL)';
17 self::assertSame('CREATE TABLE t (value VARBINARY(1)) STATS_SAMPLE_PAGES 1', (new Subject())->withoutPartitioning($sql));
18 }
19
20 public function testWithoutPartitioningPreservesQuotedKeywordsAndNestedTypes(): void
21 {
22 $sql = "CREATE TABLE t (note TEXT DEFAULT 'PARTITION BY (x)', amount DECIMAL(8, 2))";
23 self::assertSame($sql, (new Subject())->withoutPartitioning($sql));
24 }
25
26 public function testWithoutPartitioningLeavesStatementsWithoutAColumnListAlone(): void
27 {
28 self::assertSame('CREATE TABLE t LIKE other', (new Subject())->withoutPartitioning('CREATE TABLE t LIKE other'));
29 }
30
31 public function testWithoutPartitioningPreservesMultibyteIdentifiers(): void
32 {
33 $sql = 'CREATE TABLE `猫` (`名前` INT) PARTITION BY HASH (`名前`) PARTITIONS 2';
34 self::assertSame('CREATE TABLE `猫` (`名前` INT)', (new Subject())->withoutPartitioning($sql));
35 }
36
37 public function testWithoutPartitioningPreservesCommentsAndLineBreaks(): void
38 {
39 $sql = 'CREATE TABLE t (id INT) /* PARTITION BY (x) */ ENGINE=InnoDB';
40 self::assertSame($sql, (new Subject())->withoutPartitioning($sql));
41 }
42}
43