packages/sql-semantics-postgres/tests/Unit/Statement/Utility/CallTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Utility;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Semantics;
11use SqlSemantics\Platform\PostgreSql\Statement\Utility\Call;
12
13#[CoversClass(Call::class)]
14#[Medium]
15final class CallTest extends TestCase
16{
17 public function testDeriveStatementLeavesTheRowOpenOnTheProcedure(): void
18 {
19 $operation = (new Semantics())->analyze('CALL app.p(1, b => 2)');
20 self::assertSame([false, ['the signature of routine p']], [$operation->shape()?->complete(), array_map(static fn (\SqlSemantics\Platform\PostgreSql\Model\Statement\Reference\Missing\MissingInput $missing): string => $missing->describe(), $operation->shape()->missing ?? [])]);
21 }
22
23 public function testDeriveStatementDerivesTheArguments(): void
24 {
25 $operation = (new Semantics())->analyze("CALL p('a' || 1)");
26 self::assertInstanceOf(Call::class, $operation->statement);
27 self::assertTrue($operation->facts->covers($operation->statement->call));
28 self::assertSame([], $operation->facts->diagnostics);
29 }
30
31 public function testRenderWritesTheCall(): void
32 {
33 self::assertSame('CALL s.p(1, x => 2)', (new Semantics())->analyze('call S.p(1, x => 2)')->toString());
34 }
35}
36