packages/sql-semantics-postgres/tests/Unit/Statement/Routine/Option/RoutineAttributeTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Routine\Option;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Construction\Derivation;
11use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
12use SqlSemantics\Platform\PostgreSql\Model\Contract\LanguageProfile;
13use SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical;
14use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
15use SqlSemantics\Platform\PostgreSql\Platform;
16use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
17use SqlSemantics\Platform\PostgreSql\Statement\Routine\Option\RoutineAttribute;
18
19#[CoversClass(RoutineAttribute::class)]
20#[Small]
21final class RoutineAttributeTest extends TestCase
22{
23 public function testAlterableExcludesWindow(): void
24 {
25 self::assertSame([true, false], [RoutineAttribute::Strict->alterable(), RoutineAttribute::Window->alterable()]);
26 }
27
28 public function testSettingGroupsTheSpellingsOfOneAttribute(): void
29 {
30 self::assertSame(['strict', 'strict', 'volatility', 'security', 'leakproof', 'window'], [RoutineAttribute::CalledOnNullInput->setting(), RoutineAttribute::Strict->setting(), RoutineAttribute::Stable->setting(), RoutineAttribute::SecurityInvoker->setting(), RoutineAttribute::NotLeakproof->setting(), RoutineAttribute::Window->setting()]);
31 }
32
33 public function testDeriveClauseRecordsNothing(): void
34 {
35 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
36 RoutineAttribute::Immutable->deriveClause($derivation, $derivation->environment());
37 self::assertSame([], $derivation->facts()->diagnostics);
38 }
39
40 public function testRenderWritesTheKeywords(): void
41 {
42 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
43 RoutineAttribute::ReturnsNullOnNullInput->render($out);
44 self::assertSame('RETURNS NULL ON NULL INPUT', (new Lexical())->join($out->pieces()));
45 }
46}
47