packages/sql-semantics-postgres/tests/Unit/Statement/Table/Alter/Option/ColumnForeignOptionsTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table\Alter\Option;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Table\Alter\Option\ColumnForeignOptions::class)]
12#[Medium]
13final class ColumnForeignOptionsTest extends TestCase
14{
15 public function testDeriveClauseChecksTheColumn(): void
16 {
17 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
18 $context = [];
19 array_push($context, ...$semantics->inspect('CREATE FOREIGN TABLE t (a int NOT NULL, b int, c text) SERVER x')->declarations());
20 $statement = $semantics->inspect('ALTER FOREIGN TABLE t ALTER zz OPTIONS (ADD x \'y\')', $context);
21 self::assertSame([
22 0 => 'column "zz" does not exist',
23 ], array_map(static fn ($problem): string => $problem->message(), $statement->facts->diagnostics));
24 }
25
26 public function testRenderWritesTheClauseAsWritten(): void
27 {
28 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
29 $statement = $semantics->inspect('ALTER FOREIGN TABLE f ALTER a OPTIONS (SET x \'y\', DROP z)', []);
30 self::assertSame('ALTER FOREIGN TABLE f ALTER a OPTIONS (SET x \'y\', DROP z)', $statement->toString());
31 }
32}
33