packages/sql-semantics-postgres/tests/Unit/Statement/Object/Reference/RelationTargetTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Object\Reference;
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\Model\Statement\Identifier\QualifiedName;
17use SqlSemantics\Platform\PostgreSql\Platform;
18use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
19use SqlSemantics\Platform\PostgreSql\Statement\Name\RelationReference;
20use SqlSemantics\Platform\PostgreSql\Statement\Object\Reference\RelationTarget;
21
22#[CoversClass(RelationTarget::class)]
23#[Small]
24final class RelationTargetTest extends TestCase
25{
26    public function testDeriveClauseRecordsNothing(): void
27    {
28        $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
29        (new RelationTarget(new RelationReference(new QualifiedName(new Name('t')))))->deriveClause($derivation, $derivation->environment());
30        self::assertSame([], $derivation->facts()->diagnostics);
31    }
32
33    public function testRenderWritesOnly(): void
34    {
35        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
36        (new RelationTarget(new RelationReference(new QualifiedName(new Name('t')), true)))->render($out);
37        self::assertSame('ONLY t', (new Lexical())->join($out->pieces()));
38    }
39}
40