packages/sql-semantics-postgres/tests/Unit/Statement/Constraint/ConstraintAttributeTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Constraint;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Constraint\ConstraintAttribute::class)]
12#[Medium]
13final class ConstraintAttributeTest extends TestCase
14{
15    public function testDeferralIsTrueForTheDeferralAttributes(): void
16    {
17        self::assertSame([
18          0 => true,
19          1 => false,
20        ], [\SqlSemantics\Platform\PostgreSql\Statement\Constraint\ConstraintAttribute::InitiallyDeferred->deferral(), \SqlSemantics\Platform\PostgreSql\Statement\Constraint\ConstraintAttribute::NotValid->deferral()]);
21    }
22
23    public function testDeriveClauseHasNoOperand(): void
24    {
25        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
26        $statement = $semantics->inspect('CREATE TABLE t (a int REFERENCES u DEFERRABLE)', []);
27        self::assertSame(1, count($statement->facts->diagnostics));
28    }
29
30    public function testRenderWritesTheClauseAsWritten(): void
31    {
32        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
33        $statement = $semantics->inspect('CREATE TABLE t (a int, CHECK (a > 0) NOT VALID NO INHERIT, UNIQUE (a) NOT DEFERRABLE INITIALLY IMMEDIATE)', []);
34        self::assertSame('CREATE TABLE t (a INT, CHECK (a > 0) NOT VALID NO INHERIT, UNIQUE (a) NOT DEFERRABLE INITIALLY IMMEDIATE)', $statement->toString());
35    }
36}
37