packages/sql-semantics-sqlite/tests/Unit/Statement/Schema/Column/CollationTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Schema\Column;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Semantics;
11use SqlSemantics\Platform\Sqlite\Statement\Schema\Column\Collation;
12use SqlSemantics\Platform\Sqlite\Statement\Schema\CreateTable;
13
14#[CoversClass(Collation::class)]
15#[Medium]
16final class CollationTest extends TestCase
17{
18    public function testDeriveConstraintRecordsNothingForAnUnknownCollation(): void
19    {
20        $operation = (new Semantics())->analyze('CREATE TABLE t (a COLLATE no_such_collation)', []);
21
22        self::assertSame([], $operation->facts->diagnostics);
23    }
24
25    public function testRenderKeepsTheCollationName(): void
26    {
27        $operation = (new Semantics())->analyze('create table t (a text collate "RTRIM")');
28        $statement = $operation->statement;
29
30        self::assertInstanceOf(CreateTable::class, $statement);
31        self::assertInstanceOf(Collation::class, $statement->columns[0]->constraints[0]);
32        self::assertSame('RTRIM', $statement->columns[0]->constraints[0]->name->value);
33        self::assertSame('CREATE TABLE t (a text COLLATE RTRIM)', $operation->toString());
34    }
35}
36