packages/sql-semantics-postgres/tests/Unit/Statement/Object/ChangeOwnerTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Object;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\PostgreSql\Semantics;
12use SqlSemantics\Platform\PostgreSql\Statement\Name\ObjectKind;
13use SqlSemantics\Platform\PostgreSql\Statement\Name\RoleSpec;
14use SqlSemantics\Platform\PostgreSql\Statement\Name\RoleSpecKind;
15use SqlSemantics\Platform\PostgreSql\Statement\Object\ChangeOwner;
16use SqlSemantics\Platform\PostgreSql\Statement\Object\Reference\UnqualifiedName;
17
18#[CoversClass(ChangeOwner::class)]
19#[Medium]
20final class ChangeOwnerTest extends TestCase
21{
22 public function testDeriveStatementRecordsNothingForASchema(): void
23 {
24 $operation = (new Semantics())->analyze('ALTER SCHEMA s OWNER TO r', []);
25 self::assertSame([], $operation->facts->diagnostics);
26 }
27
28 public function testRenderWritesTheOwner(): void
29 {
30 $operation = (new Semantics())->analyze('ALTER LARGE OBJECT 12 OWNER TO SESSION_USER');
31 self::assertSame('ALTER LARGE OBJECT 12 OWNER TO SESSION_USER', $operation->toString());
32 }
33
34 public function testRejectsAKindWithoutOwner(): void
35 {
36 $this->expectExceptionMessage('OWNER TO names the object as the grammar names objects of its kind.');
37 new ChangeOwner(ObjectKind::Extension, new UnqualifiedName(new Name('e')), new RoleSpec(RoleSpecKind::CurrentUser));
38 }
39}
40