packages/sql-semantics-postgres/tests/Unit/Statement/Utility/Session/ShowTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Utility\Session;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Utility\Session\Show::class)]
12#[Medium]
13final class ShowTest extends TestCase
14{
15    public function testDeriveStatementRecordsTheColumnsOfShowAll(): void
16    {
17        $operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW ALL');
18        self::assertSame(['name', 'setting', 'description'], [$operation->field(0)->name?->value, $operation->field(1)->name?->value, $operation->field(2)->name?->value]);
19        self::assertSame([\SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::NotNull, \SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::Nullable], [$operation->field(0)->nullability, $operation->field(2)->nullability]);
20    }
21
22    public function testDeriveStatementNamesTheColumnOfAKeywordForm(): void
23    {
24        self::assertSame(['TimeZone', 'transaction_isolation', 'session_authorization'], [(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW TIME ZONE')->field(0)->name?->value, (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW TRANSACTION ISOLATION LEVEL')->field(0)->name?->value, (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW SESSION AUTHORIZATION')->field(0)->name?->value]);
25    }
26
27    public function testDeriveStatementLeavesTheRowOfANamedParameterOpen(): void
28    {
29        $operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW a.b');
30        self::assertFalse($operation->shape()?->complete());
31        self::assertSame('the session state: the registered name of the configuration parameter a.b', $operation->shape()->missing[0]->describe());
32    }
33
34    public function testRenderWritesEachForm(): void
35    {
36        self::assertSame(['SHOW ALL', 'SHOW a', 'SHOW TIME ZONE'], [(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW ALL')->toString(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('show A')->toString(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SHOW TIME ZONE')->toString()]);
37    }
38}
39