packages/sql-semantics-postgres/tests/Unit/Statement/Routine/Option/SupportFunctionTest.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\Name\DottedName;
19use SqlSemantics\Platform\PostgreSql\Statement\Routine\Option\SupportFunction;
20
21#[CoversClass(SupportFunction::class)]
22#[Small]
23final class SupportFunctionTest extends TestCase
24{
25 public function testAlterableIsTrue(): void
26 {
27 self::assertTrue((new SupportFunction(new DottedName([new Name('s')])))->alterable());
28 }
29
30 public function testSettingIsSupport(): void
31 {
32 self::assertSame('support', (new SupportFunction(new DottedName([new Name('s')])))->setting());
33 }
34
35 public function testDeriveClauseRecordsNothing(): void
36 {
37 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
38 (new SupportFunction(new DottedName([new Name('s')])))->deriveClause($derivation, $derivation->environment());
39 self::assertSame([], $derivation->facts()->diagnostics);
40 }
41
42 public function testRenderWritesSupport(): void
43 {
44 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
45 (new SupportFunction(new DottedName([new Name('app'), new Name('s')])))->render($out);
46 self::assertSame('SUPPORT app.s', (new Lexical())->join($out->pieces()));
47 }
48}
49