packages/sql-semantics-postgres/tests/Unit/Statement/Option/KeywordWordTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Option;
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\Option\KeywordWord;
19
20#[CoversClass(KeywordWord::class)]
21#[Small]
22final class KeywordWordTest extends TestCase
23{
24 public function testDeriveClauseRecordsNothing(): void
25 {
26 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
27 (new KeywordWord(new Name('none')))->deriveClause($derivation, $derivation->environment());
28 self::assertSame([], $derivation->facts()->diagnostics);
29 }
30
31 public function testRenderWritesTheKeywordBare(): void
32 {
33 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
34 (new KeywordWord(new Name('true')))->render($out);
35 self::assertSame('TRUE', (new Lexical())->join($out->pieces()));
36 }
37
38 public function testRejectsAWordThatIsNotReserved(): void
39 {
40 $this->expectExceptionMessage('A keyword value is a reserved keyword or none.');
41 new KeywordWord(new Name('abort'));
42 }
43}
44