packages/sql-semantics-postgres/tests/Unit/Rules/Access/MembershipChecksTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Access;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Rules\Access\MembershipChecks::class)]
12#[Medium]
13final class MembershipChecksTest extends TestCase
14{
15    public function testRolesReportsColumnsAndPublic(): void
16    {
17        self::assertSame(['column names cannot be included in GRANT/REVOKE ROLE', 'role "public" does not exist'], array_map(static fn (\SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic $diagnostic): string => $diagnostic->message(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('GRANT a (c) TO PUBLIC')->facts->diagnostics));
18    }
19
20    public function testOptionReportsTheName(): void
21    {
22        self::assertSame(['unrecognized role option "Admin"'], array_map(static fn (\SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic $diagnostic): string => $diagnostic->message(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('GRANT a TO b WITH "Admin" TRUE')->facts->diagnostics));
23    }
24}
25