packages/sql-semantics-postgres/tests/Unit/Rules/Catalog/DomainChecksTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Catalog;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Rules\Catalog\DomainChecks::class)]
12#[Medium]
13final class DomainChecksTest extends TestCase
14{
15 public function testConstraintsReportsTwoDefaults(): void
16 {
17 self::assertSame('multiple default expressions', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DOMAIN d int4 DEFAULT 1 DEFAULT 2')->facts->diagnostics[0]->message());
18 }
19
20 public function testConstraintsReportsDeferrability(): void
21 {
22 self::assertSame('specifying constraint deferrability not supported for domains', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DOMAIN d int4 NOT NULL DEFERRABLE')->facts->diagnostics[0]->message());
23 }
24
25 public function testRuleOfAForeignKey(): void
26 {
27 self::assertSame(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Problem\CatalogMisuseRule::DomainForeignKey, (new \SqlSemantics\Platform\PostgreSql\Rules\Catalog\DomainChecks())->rule(\SqlSemantics\Platform\PostgreSql\Statement\Constraint\ConstraintKind::ForeignKey));
28 }
29
30 public function testRuleAcceptsACheck(): void
31 {
32 self::assertNull((new \SqlSemantics\Platform\PostgreSql\Rules\Catalog\DomainChecks())->rule(\SqlSemantics\Platform\PostgreSql\Statement\Constraint\ConstraintKind::Check));
33 }
34
35 public function testAttributesAcceptsTheDefaults(): void
36 {
37 self::assertSame([], (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER DOMAIN d ADD CHECK (VALUE > 0) NOT DEFERRABLE INITIALLY IMMEDIATE')->facts->diagnostics);
38 }
39}
40