packages/sql-semantics-postgres/tests/Unit/Statement/Table/Problem/DefinitionProblemTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table\Problem;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Table\Problem\DefinitionProblem::class)]
12#[Medium]
13final class DefinitionProblemTest extends TestCase
14{
15    public function testMessageNamesTheSubject(): void
16    {
17        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
18        $statement = $semantics->inspect('CREATE TABLE t (a int, a int)', []);
19        $n1 = $statement->facts->diagnostics[0];
20        self::assertInstanceOf(\SqlSemantics\Platform\PostgreSql\Statement\Table\Problem\DefinitionProblem::class, $n1);
21        self::assertSame('column "a" specified more than once', $n1->message());
22    }
23
24    public function testMessageNamesTheSubjectAndItsRelation(): void
25    {
26        $problem = new \SqlSemantics\Platform\PostgreSql\Statement\Table\Problem\DefinitionProblem(\SqlSemantics\Platform\PostgreSql\Statement\Table\Problem\DefinitionRule::IdentityNullable, new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a'), new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('t'));
27        self::assertSame('column "a" of relation "t" must be declared NOT NULL before identity can be added', $problem->message());
28    }
29}
30