packages/sql-semantics-postgres/tests/Unit/Statement/Invocation/Json/Query/JsonWrappingTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Invocation\Json\Query;
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\Platform;
16use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
17use SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Query\JsonWrapperKind;
18use SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Query\JsonWrapping;
19
20#[CoversClass(JsonWrapping::class)]
21#[Small]
22final class JsonWrappingTest extends TestCase
23{
24    public function testDeriveClauseDerivesNothing(): void
25    {
26        $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
27        (new JsonWrapping(JsonWrapperKind::Without))->deriveClause($derivation, $derivation->environment());
28        self::assertSame([], $derivation->facts()->diagnostics);
29    }
30
31    public function testRenderWritesTheWrapper(): void
32    {
33        $wrapping = new JsonWrapping(JsonWrapperKind::Conditional);
34        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
35        $wrapping->render($out);
36        self::assertSame('WITH CONDITIONAL WRAPPER', (new Lexical())->join($out->pieces()));
37    }
38}
39