packages/sql-semantics-postgres/tests/Unit/Rules/Table/AttributesTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Table;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Rules\Table\Attributes::class)]
12#[Medium]
13final class AttributesTest extends TestCase
14{
15    public function testCheckedRefusesAnotherValue(): void
16    {
17        $this->expectExceptionMessage('Constraint attributes are attribute values.');
18        (new \SqlSemantics\Platform\PostgreSql\Rules\Table\Attributes())->checked([\SqlSemantics\Platform\PostgreSql\Statement\Table\View\RuleEvent::Insert]);
19    }
20
21    public function testReportReportsConflictsAndAttributesTheKindDoesNotAdmit(): void
22    {
23        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
24        $statement = $semantics->inspect('CREATE TABLE n (a int, CHECK (a > 0) DEFERRABLE NOT DEFERRABLE, UNIQUE (a) INITIALLY DEFERRED INITIALLY IMMEDIATE)', []);
25        self::assertSame([
26          0 => 'conflicting constraint properties',
27          1 => 'CHECK constraints cannot be marked DEFERRABLE',
28          2 => 'conflicting constraint properties',
29        ], array_map(static fn ($problem): string => $problem->message(), $statement->facts->diagnostics));
30    }
31}
32