packages/sql-semantics-postgres/tests/Unit/Statement/Table/Alter/AlterConstraintTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table\Alter;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Table\Alter\AlterConstraint::class)]
12#[Medium]
13final class AlterConstraintTest extends TestCase
14{
15 public function testDeriveClauseChecksTheAttributes(): void
16 {
17 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
18 $statement = $semantics->inspect('ALTER TABLE t ALTER CONSTRAINT f NOT DEFERRABLE INITIALLY DEFERRED', []);
19 self::assertSame([
20 0 => 'Relation t does not exist.',
21 1 => 'constraint declared INITIALLY DEFERRED must be DEFERRABLE',
22 ], array_map(static fn ($problem): string => $problem->message(), $statement->facts->diagnostics));
23 }
24
25 public function testRenderWritesTheClauseAsWritten(): void
26 {
27 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
28 $statement = $semantics->inspect('ALTER TABLE t ALTER CONSTRAINT f DEFERRABLE INITIALLY IMMEDIATE', []);
29 self::assertSame('ALTER TABLE t ALTER CONSTRAINT f DEFERRABLE INITIALLY IMMEDIATE', $statement->toString());
30 }
31}
32