packages/sql-semantics-postgres/tests/Unit/Statement/Constraint/Reference/ReferentialActionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Constraint\Reference;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Constraint\Reference\ReferentialAction::class)]
12#[Medium]
13final class ReferentialActionTest extends TestCase
14{
15 public function testRenderWritesTheClauseAsWritten(): void
16 {
17 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
18 $statement = $semantics->inspect('CREATE TABLE t (a int, b int, FOREIGN KEY (a, b) REFERENCES u ON DELETE SET DEFAULT (b) ON UPDATE NO ACTION)', []);
19 self::assertSame('CREATE TABLE t (a INT, b INT, FOREIGN KEY (a, b) REFERENCES u ON DELETE SET DEFAULT (b) ON UPDATE NO ACTION)', $statement->toString());
20 }
21
22 public function testRefusesColumnsForAnActionThatSetsNothing(): void
23 {
24 $this->expectExceptionMessage('Only SET NULL and SET DEFAULT name columns.');
25 new \SqlSemantics\Platform\PostgreSql\Statement\Constraint\Reference\ReferentialAction(\SqlSemantics\Platform\PostgreSql\Statement\Constraint\Reference\ReferenceEvent::Delete, \SqlSemantics\Platform\PostgreSql\Statement\Constraint\Reference\ReferenceAction::Cascade, [new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')]);
26 }
27}
28