packages/sql-semantics-mysql/tests/Unit/Statement/Table/Column/CollateAttributeTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table\Column;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Semantics;
11use SqlSemantics\Platform\MySql\Statement\Table\Column\CollateAttribute;
12use SqlSemantics\Platform\MySql\Statement\Table\Column\ColumnDefinition;
13use SqlSemantics\Platform\MySql\Statement\Table\CreateTable;
14
15#[CoversClass(CollateAttribute::class)]
16#[Medium]
17final class CollateAttributeTest extends TestCase
18{
19 public function testDeriveAttributeDerivesNothing(): void
20 {
21 $create = (new Semantics())->analyze('CREATE TABLE t (a TEXT COLLATE utf8mb4_bin)');
22 $statement = $create->statement;
23 self::assertInstanceOf(CreateTable::class, $statement);
24 $statement = $create->statement;
25 self::assertInstanceOf(CreateTable::class, $statement);
26 $column = $statement->elements[0];
27 self::assertInstanceOf(ColumnDefinition::class, $column);
28 $attribute = $column->specification->columnAttributes()[0];
29
30 self::assertInstanceOf(CollateAttribute::class, $attribute);
31 self::assertSame('utf8mb4_bin', $attribute->collation->name?->value);
32 }
33
34 public function testRenderWritesTheAttribute(): void
35 {
36 self::assertSame('CREATE TABLE t (a TEXT COLLATE utf8mb4_bin)', (new Semantics())->analyze('CREATE TABLE t (a TEXT COLLATE utf8mb4_bin)')->toString());
37 }
38}
39