packages/sql-semantics-postgres/tests/Unit/Statement/Utility/Session/SetParameterTest.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\SetParameter::class)]
12#[Medium]
13final class SetParameterTest extends TestCase
14{
15 public function testDeriveStatementRecordsNoProblem(): void
16 {
17 self::assertSame([], (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SET search_path TO a, \'b\', 1, on')->facts->diagnostics);
18 }
19
20 public function testDeriveStatementReturnsNoRows(): void
21 {
22 $operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SET a = 1');
23 self::assertSame(null, $operation->facts->output);
24 }
25
26 public function testRenderWritesToForEitherWord(): void
27 {
28 self::assertSame('SET a TO 1, \'x\', - 2.5, TRUE', (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SET a = 1, \'x\', -2.5, true')->toString());
29 }
30
31 public function testRenderDropsSessionAndKeepsLocal(): void
32 {
33 self::assertSame(['SET a TO b', 'SET LOCAL a TO b'], [(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SET SESSION a TO b')->toString(), (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SET LOCAL a TO b')->toString()]);
34 }
35
36 public function testValuesAreKeptInOrder(): void
37 {
38 $statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SET a TO x, y')->statement;
39 self::assertInstanceOf(\SqlSemantics\Platform\PostgreSql\Statement\Utility\Session\SetParameter::class, $statement);
40 self::assertCount(2, $statement->values);
41 }
42}
43