packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Access/Problem/AccessProblemTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Access\Problem;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Problem\AccessProblem::class)]
12#[Medium]
13final class AccessProblemTest extends TestCase
14{
15    public function testMessageNamesTheSubjects(): void
16    {
17        self::assertSame(['invalid privilege type EXECUTE for schema'], array_map(static fn (\SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic $diagnostic): string => $diagnostic->message(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('GRANT EXECUTE ON SCHEMA s TO joe')->facts->diagnostics));
18    }
19
20    public function testMessageWithoutSubject(): void
21    {
22        self::assertSame('conflicting or redundant options', (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Problem\AccessProblem(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Problem\AccessProblemRule::RedundantOptions))->message());
23    }
24
25    public function testRejectsAMissingSubject(): void
26    {
27        $this->expectExceptionMessage('An access problem names one subject for each place of its message.');
28        new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Problem\AccessProblem(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Problem\AccessProblemRule::ReservedRoleName);
29    }
30}
31