packages/sql-semantics-postgres/tests/Unit/Statement/Routine/ResultColumnTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Routine;
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\ResultColumn;
20use SqlSemantics\Platform\PostgreSql\Statement\Type\Designation\NamedDesignation;
21use SqlSemantics\Platform\PostgreSql\Statement\Type\TypeName;
22
23#[CoversClass(ResultColumn::class)]
24#[Small]
25final class ResultColumnTest extends TestCase
26{
27    public function testDeriveClauseRecordsNothingForAPlainType(): void
28    {
29        $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
30        (new ResultColumn(new Name('a'), new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))))->deriveClause($derivation, $derivation->environment());
31        self::assertSame([], $derivation->facts()->diagnostics);
32    }
33
34    public function testRenderWritesNameAndType(): void
35    {
36        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
37        (new ResultColumn(new Name('Id'), new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))))->render($out);
38        self::assertSame('"Id" int4', (new Lexical())->join($out->pieces()));
39    }
40}
41