packages/sql-semantics-postgres/tests/Unit/Statement/Invocation/PositionalArgumentTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Invocation;
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\Invocation\PositionalArgument;
18use SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant;
19use SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant;
20use SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral;
21
22#[CoversClass(PositionalArgument::class)]
23#[Small]
24final class PositionalArgumentTest extends TestCase
25{
26 public function testValueAnswersTheValuePassed(): void
27 {
28 $value = new Constant(new IntegerConstant('1'));
29 self::assertSame($value, (new PositionalArgument($value))->value());
30 }
31
32 public function testNameIsNull(): void
33 {
34 self::assertNull((new PositionalArgument(new NullLiteral()))->name());
35 }
36
37 public function testDeriveClauseDerivesTheValue(): void
38 {
39 $value = new Constant(new IntegerConstant('1'));
40 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
41 (new PositionalArgument($value))->deriveClause($derivation, $derivation->environment());
42 self::assertTrue($derivation->facts()->covers($value));
43 }
44
45 public function testRenderWritesTheValue(): void
46 {
47 $argument = new PositionalArgument(new Constant(new IntegerConstant('1')));
48 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
49 $argument->render($out);
50 self::assertSame('1', (new Lexical())->join($out->pieces()));
51 }
52}
53