packages/sql-semantics-postgres/tests/Unit/Statement/Name/RelationReferenceTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Name;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
11use SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical;
12use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
13use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
14use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\QualifiedName;
15use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
16use SqlSemantics\Platform\PostgreSql\Statement\Name\RelationReference;
17
18#[CoversClass(RelationReference::class)]
19#[Small]
20final class RelationReferenceTest extends TestCase
21{
22    public function testRenderWritesOnlyBeforeTheName(): void
23    {
24        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
25        (new RelationReference(new QualifiedName(new Name('t'), new Name('s')), true))->render($out);
26        self::assertSame('ONLY s.t', (new Lexical())->join($out->pieces()));
27    }
28
29    public function testRenderWritesAPlainNameWithoutOnly(): void
30    {
31        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
32        (new RelationReference(new QualifiedName(new Name('User'))))->render($out);
33        self::assertSame('"User"', (new Lexical())->join($out->pieces()));
34    }
35}
36