packages/sql-semantics-postgres/tests/Unit/Rules/Routine/AggregateChecksTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Routine;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Rules\Routine\AggregateChecks;
11use SqlSemantics\Platform\PostgreSql\Semantics;
12use SqlSemantics\Platform\PostgreSql\Statement\Routine\Problem\RoutineProblem;
13use SqlSemantics\Platform\PostgreSql\Statement\Routine\Problem\RoutineProblemKind;
14
15#[CoversClass(AggregateChecks::class)]
16#[Medium]
17final class AggregateChecksTest extends TestCase
18{
19 public function testArgumentsChecksTheVariadicOrderedSet(): void
20 {
21 $semantics = new Semantics();
22 $accepted = $semantics->inspect('DROP AGGREGATE a(VARIADIC int4[] ORDER BY VARIADIC int4[])', []);
23 $rejected = $semantics->inspect('DROP AGGREGATE a(VARIADIC int4[] ORDER BY VARIADIC text[])', []);
24 $counted = $semantics->inspect('DROP AGGREGATE a(VARIADIC int4[] ORDER BY int4, int4)', []);
25 self::assertSame([], $accepted->facts->diagnostics);
26 self::assertEquals([new RoutineProblem(RoutineProblemKind::OrderedSetVariadic)], $rejected->facts->diagnostics);
27 self::assertEquals([new RoutineProblem(RoutineProblemKind::OrderedSetVariadic)], $counted->facts->diagnostics);
28 }
29}
30