packages/sql-semantics-postgres/tests/Unit/Statement/Operator/MemberRemovalTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Operator;
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\Rendering\Lexical;
14use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
15use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
16use SqlSemantics\Platform\PostgreSql\Platform;
17use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
18use SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant;
19use SqlSemantics\Platform\PostgreSql\Statement\Name\DottedName;
20use SqlSemantics\Platform\PostgreSql\Statement\Operator\MemberKind;
21use SqlSemantics\Platform\PostgreSql\Statement\Operator\MemberRemoval;
22use SqlSemantics\Platform\PostgreSql\Statement\Type\Designation\NamedDesignation;
23use SqlSemantics\Platform\PostgreSql\Statement\Type\TypeName;
24
25#[CoversClass(MemberRemoval::class)]
26#[Small]
27final class MemberRemovalTest extends TestCase
28{
29 public function testDeriveClauseDerivesTheTypes(): void
30 {
31 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
32 (new MemberRemoval(MemberKind::Function, new IntegerConstant('1'), [new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))]))->deriveClause($derivation, $derivation->environment());
33 self::assertSame([], $derivation->facts()->diagnostics);
34 }
35
36 public function testRenderWritesKindNumberAndTypes(): void
37 {
38 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
39 (new MemberRemoval(MemberKind::Function, new IntegerConstant('1'), [new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))]))->render($out);
40 self::assertSame('FUNCTION 1 (int4)', (new Lexical())->join($out->pieces()));
41 }
42
43 public function testRejectsAnEmptyTypeList(): void
44 {
45 $this->expectExceptionMessage('A removed member names at least one operand type.');
46 new MemberRemoval(MemberKind::Operator, new IntegerConstant('1'), []);
47 }
48}
49