packages/sql-semantics-sqlite/tests/Unit/Statement/Schema/Table/TableOptionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Schema\Table;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Rendering\Lexical;
11use SqlSemantics\Platform\Sqlite\Model\Rendering\Output;
12use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
13use SqlSemantics\Platform\Sqlite\Rendering\Codec;
14use SqlSemantics\Platform\Sqlite\Statement\Lexical\Word;
15use SqlSemantics\Platform\Sqlite\Statement\Lexical\WordQuote;
16use SqlSemantics\Platform\Sqlite\Statement\Schema\Table\TableOption;
17use SqlSemantics\Platform\Sqlite\Statement\Schema\Table\TableOptionKind;
18
19#[CoversClass(TableOption::class)]
20#[Small]
21final class TableOptionTest extends TestCase
22{
23 public function testKindReadsTheTwoKnownOptionsWithoutRegardToCase(): void
24 {
25 self::assertSame(TableOptionKind::WithoutRowid, (new TableOption(new Word(new Name('RowId')), true))->kind());
26 self::assertSame(TableOptionKind::Strict, (new TableOption(new Word(new Name('strict'))))->kind());
27 }
28
29 public function testKindIsNullForEveryOtherWordAndForAQuotedWord(): void
30 {
31 self::assertNull((new TableOption(new Word(new Name('strict')), true))->kind());
32 self::assertNull((new TableOption(new Word(new Name('rowid'))))->kind());
33 self::assertNull((new TableOption(new Word(new Name('rowid'), WordQuote::Double), true))->kind());
34 self::assertNull((new TableOption(new Word(new Name('strict'), WordQuote::Single)))->kind());
35 }
36
37 public function testRenderWritesTheWordWithItsQuoting(): void
38 {
39 $lexical = new Lexical();
40 $without = new Output(new Codec());
41 (new TableOption(new Word(new Name('ROWID')), true))->render($without);
42 $quoted = new Output(new Codec());
43 (new TableOption(new Word(new Name('strict'), WordQuote::Bracket)))->render($quoted);
44
45 self::assertSame('WITHOUT ROWID', $lexical->join($without->pieces()));
46 self::assertSame('[strict]', $lexical->join($quoted->pieces()));
47 }
48}
49