packages/sql-semantics-postgres/tests/Unit/Statement/Manipulation/Prepared/ExecuteTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Manipulation\Prepared;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Prepared\Execute::class)]
12#[Medium]
13final class ExecuteTest extends TestCase
14{
15    public function testDeriveStatementRecordsRowsThatDependOnTheSession(): void
16    {
17        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
18        $query = $semantics->inspect('EXECUTE p (1)');
19        self::assertSame('the session state: the prepared statement p', $query->facts->output?->shape->missing[0]->describe());
20    }
21
22    public function testDeriveParametersReportsDefault(): void
23    {
24        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
25        $query = $semantics->inspect('EXECUTE p (DEFAULT)');
26        self::assertSame(['DEFAULT is not allowed in this context'], array_map(static fn (\SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic $diagnostic): string => $diagnostic->message(), $query->facts->diagnostics));
27    }
28
29    public function testRowsIsAnOpenShape(): void
30    {
31        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
32        $query = $semantics->inspect('EXECUTE p');
33        self::assertFalse($query->facts->output?->shape->complete());
34    }
35
36    public function testRenderWritesTheParameters(): void
37    {
38        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
39        $query = $semantics->inspect("EXECUTE p (1, 'x')");
40        self::assertSame("EXECUTE p (1, 'x')", $query->toString());
41    }
42}
43