packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Access/Owned/ReassignOwnedTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Access\Owned;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Owned\ReassignOwned::class)]
12#[Medium]
13final class ReassignOwnedTest extends TestCase
14{
15 public function testRenderWritesTheOwners(): void
16 {
17 self::assertSame('REASSIGN OWNED BY joe, SESSION_USER TO boss', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('REASSIGN OWNED BY joe, SESSION_USER TO boss')->toString());
18 }
19
20 public function testDeriveStatementReportsPublic(): void
21 {
22 self::assertSame(['role "public" does not exist', '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('REASSIGN OWNED BY PUBLIC TO PUBLIC')->facts->diagnostics));
23 }
24
25 public function testRejectsNoOwner(): void
26 {
27 $this->expectExceptionMessage('A role list names at least one role.');
28 new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Owned\ReassignOwned([], new \SqlSemantics\Platform\PostgreSql\Statement\Name\RoleSpec(\SqlSemantics\Platform\PostgreSql\Statement\Name\RoleSpecKind::Named, new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('boss')));
29 }
30}
31