packages/sql-semantics-postgres/tests/Unit/Statement/Operator/StorageMemberTest.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\Name\DottedName;
19use SqlSemantics\Platform\PostgreSql\Statement\Operator\StorageMember;
20use SqlSemantics\Platform\PostgreSql\Statement\Type\Designation\NamedDesignation;
21use SqlSemantics\Platform\PostgreSql\Statement\Type\TypeName;
22
23#[CoversClass(StorageMember::class)]
24#[Small]
25final class StorageMemberTest extends TestCase
26{
27 public function testDeriveClauseDerivesTheType(): void
28 {
29 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
30 (new StorageMember(new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))))->deriveClause($derivation, $derivation->environment());
31 self::assertSame([], $derivation->facts()->diagnostics);
32 }
33
34 public function testRenderWritesStorage(): void
35 {
36 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
37 (new StorageMember(new TypeName(new NamedDesignation(new DottedName([new Name('int4')])))))->render($out);
38 self::assertSame('STORAGE int4', (new Lexical())->join($out->pieces()));
39 }
40}
41