packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Publication/AlterPublicationMembersTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Publication;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Publication\AlterPublicationMembers::class)]
12#[Medium]
13final class AlterPublicationMembersTest extends TestCase
14{
15    public function testRenderWritesTheAction(): void
16    {
17        self::assertSame('ALTER PUBLICATION p ADD TABLE t, TABLES IN SCHEMA s', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER PUBLICATION p ADD TABLE t, TABLES IN SCHEMA s')->toString());
18    }
19
20    public function testDeriveStatementReportsAFilterOnDrop(): void
21    {
22        self::assertSame('cannot use a WHERE clause when removing a table from a publication', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER PUBLICATION p DROP TABLE t WHERE (true)')->facts->diagnostics[0]->message());
23    }
24
25    public function testDeriveStatementReportsColumnsOnDrop(): void
26    {
27        self::assertSame('column list must not be specified in ALTER PUBLICATION ... DROP', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER PUBLICATION p DROP TABLE t (a)')->facts->diagnostics[0]->message());
28    }
29
30    public function testRejectsABareTableAfterASchema(): void
31    {
32        $this->expectExceptionMessage('A bare table name continues a table item.');
33        new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Publication\AlterPublicationMembers(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('p'), \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Publication\PublicationAction::Add, [new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Publication\PublicationSchema(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('s')), new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Publication\PublicationTable(new \SqlSemantics\Platform\PostgreSql\Statement\Name\RelationReference(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('t'))), [], null, false)]);
34    }
35}
36