packages/sql-fixture/tests/Unit/Platform/MySql/Schema/DefinitionIntegrityTest.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\DefinitionIntegrity as Subject;
10
11#[CoversClass(Subject::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\SchemaParseException::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\Exception\InvalidSqlException::class)]
14#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\Exception\ExpectedCreateTableException::class)]
15#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\Exception\MissingColumnDefinitionsException::class)]
16final class DefinitionIntegrityTest extends TestCase
17{
18 public function testAssertNothingWasLostAcceptsCompleteDeclarations(): void
19 {
20 $sql = 'CREATE TABLE users (id INT NOT NULL PRIMARY KEY, amount DECIMAL(8, 2) UNSIGNED DEFAULT 12.5)';
21 $parser = new \PhpMyAdmin\SqlParser\Parser($sql);
22 $statement = $parser->statements[0];
23 self::assertInstanceOf(\PhpMyAdmin\SqlParser\Statements\CreateStatement::class, $statement);
24 (new Subject())->assertNothingWasLost($parser, $statement, $sql);
25 self::assertSame(2, (new Subject())->countDeclaredDefinitions($parser));
26 }
27
28 public function testCountDeclaredDefinitionsIgnoresNestedCommas(): void
29 {
30 $parser = new \PhpMyAdmin\SqlParser\Parser("CREATE TABLE a (id INT, status ENUM('a,b', 'c'), price DECIMAL(8, 2))");
31 self::assertSame(3, (new Subject())->countDeclaredDefinitions($parser));
32 }
33}
34