packages/sql-semantics-postgres/tests/Unit/Statement/Invocation/ArgumentTest.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\Rendering\Output;
12use SqlSemantics\Platform\PostgreSql\Model\Resolution\Environment;
13use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
14use SqlSemantics\Platform\PostgreSql\Model\Statement\Scalar;
15use SqlSemantics\Platform\PostgreSql\Statement\Invocation\Argument;
16use SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant;
17use SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant;
18
19#[CoversClass(Argument::class)]
20#[Small]
21final class ArgumentTest extends TestCase
22{
23    public function testValueIsTheExpressionPassed(): void
24    {
25        $value = new Constant(new IntegerConstant('1'));
26        $argument = new class ($value) implements Argument {
27            public function __construct(private readonly Scalar $value)
28            {
29            }
30
31            public function value(): Scalar
32            {
33                return $this->value;
34            }
35
36            public function name(): ?Name
37            {
38                return null;
39            }
40
41            public function deriveClause(Derivation $derivation, Environment $environment): void
42            {
43            }
44
45            public function render(Output $out): void
46            {
47            }
48        };
49        self::assertSame($value, $argument->value());
50    }
51
52    public function testNameIsTheParameterNamedOrNull(): void
53    {
54        $argument = new class () implements Argument {
55            public function value(): Scalar
56            {
57                return new Constant(new IntegerConstant('1'));
58            }
59
60            public function name(): Name
61            {
62                return new Name('p');
63            }
64
65            public function deriveClause(Derivation $derivation, Environment $environment): void
66            {
67            }
68
69            public function render(Output $out): void
70            {
71            }
72        };
73        self::assertSame('p', $argument->name()->value);
74    }
75}
76