packages/sql-semantics-postgres/tests/Unit/Rules/Routine/ObjectFactsTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Routine;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Construction\Derivation;
11use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
12use SqlSemantics\Platform\PostgreSql\Model\Contract\LanguageProfile;
13use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
14use SqlSemantics\Platform\PostgreSql\Platform;
15use SqlSemantics\Platform\PostgreSql\Rules\Routine\ObjectFacts;
16use SqlSemantics\Platform\PostgreSql\Statement\Name\DottedName;
17use SqlSemantics\Platform\PostgreSql\Statement\Name\ObjectKind;
18use SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName;
19use SqlSemantics\Platform\PostgreSql\Statement\Routine\Problem\RoutineProblem;
20use SqlSemantics\Platform\PostgreSql\Statement\Routine\Problem\RoutineProblemKind;
21use SqlSemantics\Platform\PostgreSql\Statement\Routine\Signature\OperatorArity;
22use SqlSemantics\Platform\PostgreSql\Statement\Routine\Signature\OperatorSignature;
23use SqlSemantics\Platform\PostgreSql\Statement\Type\Designation\NamedDesignation;
24use SqlSemantics\Platform\PostgreSql\Statement\Type\TypeName;
25
26#[CoversClass(ObjectFacts::class)]
27#[Small]
28final class ObjectFactsTest extends TestCase
29{
30 public function testDeriveReportsAPostfixOperatorWithoutIfExists(): void
31 {
32 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
33 $facts = (new ObjectFacts())->derive(ObjectKind::Operator, [new OperatorSignature(new OperatorName(new Name('!')), OperatorArity::Postfix, [new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))])], false, $derivation);
34 (new ObjectFacts())->derive(ObjectKind::Operator, [new OperatorSignature(new OperatorName(new Name('!')), OperatorArity::Postfix, [new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))])], true, $derivation);
35 self::assertSame([null], $facts);
36 self::assertEquals([new RoutineProblem(RoutineProblemKind::PostfixOperator)], $derivation->facts()->diagnostics);
37 }
38}
39