packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Access/Privilege/PrivilegeTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Access\Privilege;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\Privilege::class)]
12#[Medium]
13final class PrivilegeTest extends TestCase
14{
15 public function testPrivilegeOfAName(): void
16 {
17 self::assertSame('insert', (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\Privilege(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('insert')))->privilege());
18 }
19
20 public function testPrivilegeOfAKeyword(): void
21 {
22 self::assertSame('references', (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\Privilege(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\PrivilegeKeyword::References))->privilege());
23 }
24
25 public function testPrivilegeOfAllIsNull(): void
26 {
27 self::assertSame(null, (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\Privilege(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\PrivilegeKeyword::All, [new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')]))->privilege());
28 }
29
30 public function testRenderWritesTheNameAndTheColumns(): void
31 {
32 self::assertSame('GRANT SELECT (a, "B"), "select", update ON TABLE t TO joe', (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('GRANT select (a, "B"), "select", update ON t TO joe')->toString());
33 }
34
35 public function testRejectsAllWithoutColumns(): void
36 {
37 $this->expectExceptionMessage('ALL is a privilege of its own only with a column list.');
38 new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\Privilege(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\PrivilegeKeyword::All);
39 }
40
41 public function testRejectsColumnsOnAlterSystem(): void
42 {
43 $this->expectExceptionMessage('ALTER SYSTEM takes no column list.');
44 new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\Privilege(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Privilege\PrivilegeKeyword::AlterSystem, [new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')]);
45 }
46}
47