packages/sql-semantics-postgres/tests/Unit/Statement/Object/SecurityLabelTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Object;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\PostgreSql\Semantics;
12use SqlSemantics\Platform\PostgreSql\Statement\Name\ObjectKind;
13use SqlSemantics\Platform\PostgreSql\Statement\Object\Reference\UnqualifiedName;
14use SqlSemantics\Platform\PostgreSql\Statement\Object\SecurityLabel;
15
16#[CoversClass(SecurityLabel::class)]
17#[Medium]
18final class SecurityLabelTest extends TestCase
19{
20    public function testDeriveStatementResolvesALabelledTable(): void
21    {
22        $operation = (new Semantics())->inspect('SECURITY LABEL ON TABLE t IS NULL', []);
23        self::assertSame(['Relation t does not exist.'], [$operation->facts->diagnostics[0]->message()]);
24    }
25
26    public function testRenderWritesTheProvider(): void
27    {
28        $operation = (new Semantics())->inspect("SECURITY LABEL FOR 'sepgsql' ON FUNCTION f(int4) IS 'l'");
29        self::assertSame("SECURITY LABEL FOR 'sepgsql' ON FUNCTION f (int4) IS 'l'", $operation->toString());
30    }
31
32    public function testRejectsAKindWithoutLabels(): void
33    {
34        $this->expectExceptionMessage('SECURITY LABEL names the object as the grammar names objects of its kind.');
35        new SecurityLabel(ObjectKind::Rule, new UnqualifiedName(new Name('r')), null);
36    }
37}
38