packages/sql-semantics-postgres/tests/Unit/Statement/Object/Reference/TransformForTest.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\Platform;
17use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
18use SqlSemantics\Platform\PostgreSql\Statement\Name\DottedName;
19use SqlSemantics\Platform\PostgreSql\Statement\Object\Reference\TransformFor;
20use SqlSemantics\Platform\PostgreSql\Statement\Type\Designation\NamedDesignation;
21use SqlSemantics\Platform\PostgreSql\Statement\Type\TypeName;
22
23#[CoversClass(TransformFor::class)]
24#[Small]
25final class TransformForTest extends TestCase
26{
27    public function testDeriveClauseDerivesTheType(): void
28    {
29        $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
30        (new TransformFor(new TypeName(new NamedDesignation(new DottedName([new Name('int4')]))), new Name('plperl')))->deriveClause($derivation, $derivation->environment());
31        self::assertSame([], $derivation->facts()->diagnostics);
32    }
33
34    public function testRenderWritesTypeAndLanguage(): void
35    {
36        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
37        (new TransformFor(new TypeName(new NamedDesignation(new DottedName([new Name('int4')]))), new Name('plperl')))->render($out);
38        self::assertSame('FOR int4 LANGUAGE plperl', (new Lexical())->join($out->pieces()));
39    }
40}
41