packages/sql-semantics-postgres/tests/Unit/Rules/Query/AliasSpellingTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Query;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Rules\Query\AliasSpelling::class)]
12#[Small]
13final class AliasSpellingTest extends TestCase
14{
15    public function testWriteWritesAsTheAliasAndColumns(): void
16    {
17        $out = new \SqlSemantics\Platform\PostgreSql\Model\Rendering\Output(new \SqlSemantics\Platform\PostgreSql\Rendering\Codec(\SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease::PostgreSql172));
18        (new \SqlSemantics\Platform\PostgreSql\Rules\Query\AliasSpelling())->write($out, new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('x'), [new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a'), new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('B')]);
19        self::assertSame('AS x (a, "B")', (new \SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical())->join($out->pieces()));
20    }
21
22    public function testNamesWritesNothingForNoName(): void
23    {
24        $out = new \SqlSemantics\Platform\PostgreSql\Model\Rendering\Output(new \SqlSemantics\Platform\PostgreSql\Rendering\Codec(\SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease::PostgreSql172));
25        (new \SqlSemantics\Platform\PostgreSql\Rules\Query\AliasSpelling())->names($out, []);
26        self::assertSame([], $out->pieces());
27    }
28}
29