packages/sql-semantics-postgres/tests/Unit/Rules/Invocation/RoutineMatchTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Invocation;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Rules\Invocation\RoutineMatch;
11
12#[CoversClass(RoutineMatch::class)]
13#[Small]
14final class RoutineMatchTest extends TestCase
15{
16    public function testFindAcceptsOnlyExactMatchesWhenEverySchemaIsSearched(): void
17    {
18        $match = new RoutineMatch();
19        self::assertSame('text', $match->find('upper', ['unknown'], false)[0] ?? null);
20        self::assertNull($match->find('upper', ['varchar'], false));
21        self::assertSame('text', $match->find('upper', ['varchar'], true)[0] ?? null);
22    }
23
24    public function testFindLeavesAnAmbiguousCallUndecided(): void
25    {
26        self::assertNull((new RoutineMatch())->find('extract', ['unknown', 'unknown'], true));
27    }
28
29    public function testPreferredKeepsTextForUnknownArguments(): void
30    {
31        $rows = [['text', 's', 'P', ['text']], ['bytea', 's', 'P', ['bytea']]];
32        self::assertSame([$rows[0]], (new RoutineMatch())->preferred($rows, ['unknown']));
33    }
34
35    public function testSingleAnswersOnlyAUniqueCandidate(): void
36    {
37        $row = ['text', 's', 'P', ['text']];
38        self::assertSame([$row, null], [(new RoutineMatch())->single([$row]), (new RoutineMatch())->single([$row, $row])]);
39    }
40}
41