packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Access/Role/RolePasswordTest.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\RolePassword::class)]
12#[Medium]
13final class RolePasswordTest extends TestCase
14{
15 public function testOption(): void
16 {
17 self::assertSame('password', (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RolePassword(null))->option());
18 }
19
20 public function testRenderDropsTheNoiseWordEncrypted(): void
21 {
22 self::assertSame('ALTER ROLE r PASSWORD \'x\'', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER ROLE r ENCRYPTED PASSWORD \'x\'')->toString());
23 }
24
25 public function testRenderWritesNull(): void
26 {
27 self::assertSame('ALTER ROLE r PASSWORD NULL', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER ROLE r PASSWORD NULL')->toString());
28 }
29
30 public function testRenderKeepsUnencrypted(): void
31 {
32 self::assertSame('ALTER ROLE r UNENCRYPTED PASSWORD \'x\'', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('ALTER ROLE r UNENCRYPTED PASSWORD \'x\'')->toString());
33 }
34
35 public function testRejectsUnencryptedWithoutAPassword(): void
36 {
37 $this->expectExceptionMessage('UNENCRYPTED PASSWORD is followed by a password.');
38 new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RolePassword(null, true);
39 }
40}
41