packages/sql-semantics-postgres/tests/Unit/Statement/Relation/Json/JsonExistsColumnTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Relation\Json;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Relation\Json\JsonExistsColumn::class)]
12#[Medium]
13final class JsonExistsColumnTest extends TestCase
14{
15    public function testRenderWritesExistsAndThePath(): void
16    {
17        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
18        $query = $semantics->analyze("SELECT * FROM JSON_TABLE ('[]', '\$[*]' COLUMNS (e boolean EXISTS PATH '\$.e'))");
19        self::assertSame("SELECT * FROM JSON_TABLE ('[]', '\$[*]' COLUMNS (e BOOLEAN EXISTS PATH '\$.e'))", $query->toString());
20    }
21
22    public function testRenderQuotesAColumnNamedNested(): void
23    {
24        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
25        $query = $semantics->analyze("SELECT * FROM JSON_TABLE ('[]', '\$[*]' COLUMNS (\"nested\" path EXISTS))");
26        self::assertSame("SELECT * FROM JSON_TABLE ('[]', '\$[*]' COLUMNS (\"nested\" path EXISTS))", $query->toString());
27    }
28}
29