packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Access/Role/DropRoleTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Access\Role;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\DropRole::class)]
12#[Medium]
13final class DropRoleTest extends TestCase
14{
15 public function testRenderWritesTheWordAndIfExists(): void
16 {
17 self::assertSame('DROP USER IF EXISTS joe, ann', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('DROP USER IF EXISTS joe, ann')->toString());
18 }
19
20 public function testRenderWritesTheGroupWord(): void
21 {
22 self::assertSame('DROP GROUP staff', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('DROP GROUP staff')->toString());
23 }
24
25 public function testDeriveStatementReportsEveryDesignation(): void
26 {
27 self::assertSame(['cannot use special role specifier in DROP ROLE', 'cannot use special role specifier in DROP ROLE'], array_map(static fn (\SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic $diagnostic): string => $diagnostic->message(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('DROP ROLE joe, CURRENT_USER, public')->facts->diagnostics));
28 }
29
30 public function testRejectsNoRole(): void
31 {
32 $this->expectExceptionMessage('A role list names at least one role.');
33 new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\DropRole(\SqlSemantics\Platform\PostgreSql\Statement\Object\RoleWord::Role, []);
34 }
35}
36