packages/sql-fixture/tests/Unit/Platform/PostgreSql/Schema/ColumnParserTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Platform\PostgreSql\Schema;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use SqlFixture\Platform\PostgreSql\Schema\ColumnParser as Subject;
10
11#[CoversClass(Subject::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Platform\PostgreSql\Schema\DefaultExpression::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Platform\PostgreSql\Schema\TypeDeclaration::class)]
14#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\ColumnDefinition::class)]
15#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\TypeShape::class)]
16final class ColumnParserTest extends TestCase
17{
18 public function testParseColumnDefinitionReadsConstraintsAndDecimalShape(): void
19 {
20 $column = (new Subject())->parseColumnDefinition('amount NUMERIC(8, 2) NOT NULL DEFAULT 12.5', []);
21 self::assertNotNull($column);
22 self::assertSame('amount', $column->name);
23 self::assertSame('NUMERIC', $column->type);
24 self::assertSame(8, $column->precision);
25 self::assertSame(2, $column->scale);
26 self::assertFalse($column->nullable);
27 self::assertSame(12.5, $column->default);
28 }
29
30 public function testParseColumnDefinitionAppliesTablePrimaryKey(): void
31 {
32 $column = (new Subject())->parseColumnDefinition('id INTEGER', ['id']);
33 self::assertNotNull($column);
34 self::assertFalse($column->nullable);
35 }
36}
37