packages/sql-semantics-postgres/tests/Unit/Statement/Routine/Option/RoutineDefinitionTest.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\Model\Statement\Identifier\Name;
16use SqlSemantics\Platform\PostgreSql\Platform;
17use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
18use SqlSemantics\Platform\PostgreSql\Statement\Literal\StringConstant;
19use SqlSemantics\Platform\PostgreSql\Statement\Routine\Option\RoutineDefinition;
20use SqlSemantics\Platform\PostgreSql\Statement\Routine\Option\RoutineSource;
21
22#[CoversClass(RoutineDefinition::class)]
23#[Small]
24final class RoutineDefinitionTest extends TestCase
25{
26 public function testAlterableIsFalse(): void
27 {
28 self::assertFalse((new RoutineDefinition(new RoutineSource(new Name('sql'), new StringConstant('x'))))->alterable());
29 }
30
31 public function testSettingIsAs(): void
32 {
33 self::assertSame('as', (new RoutineDefinition(new RoutineSource(new Name('sql'), new StringConstant('x'))))->setting());
34 }
35
36 public function testDeriveClauseRecordsNothing(): void
37 {
38 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
39 (new RoutineDefinition(new RoutineSource(new Name('sql'), new StringConstant('x'))))->deriveClause($derivation, $derivation->environment());
40 self::assertSame([], $derivation->facts()->diagnostics);
41 }
42
43 public function testRenderWritesFileAndSymbol(): void
44 {
45 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
46 (new RoutineDefinition(new RoutineSource(new Name('c'), new StringConstant('lib')), new StringConstant("it's")))->render($out);
47 self::assertSame("AS 'lib', 'it''s'", (new Lexical())->join($out->pieces()));
48 }
49}
50