packages/sql-semantics-mysql/tests/Unit/Statement/Table/Column/FormatAttributeTest.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\ColumnDefinition;
12use SqlSemantics\Platform\MySql\Statement\Table\Column\FormatAttribute;
13use SqlSemantics\Platform\MySql\Statement\Table\Column\Kind\ColumnFormat;
14use SqlSemantics\Platform\MySql\Statement\Table\CreateTable;
15
16#[CoversClass(FormatAttribute::class)]
17#[Medium]
18final class FormatAttributeTest extends TestCase
19{
20 public function testDeriveAttributeDerivesNothing(): void
21 {
22 $create = (new Semantics())->analyze('CREATE TABLE t (a INT COLUMN_FORMAT DYNAMIC)');
23 $statement = $create->statement;
24 self::assertInstanceOf(CreateTable::class, $statement);
25 $statement = $create->statement;
26 self::assertInstanceOf(CreateTable::class, $statement);
27 $column = $statement->elements[0];
28 self::assertInstanceOf(ColumnDefinition::class, $column);
29 $attribute = $column->specification->columnAttributes()[0];
30
31 self::assertInstanceOf(FormatAttribute::class, $attribute);
32 self::assertSame(ColumnFormat::Dynamic, $attribute->format);
33 }
34
35 public function testRenderWritesTheAttribute(): void
36 {
37 self::assertSame('CREATE TABLE t (a INT COLUMN_FORMAT DYNAMIC)', (new Semantics())->analyze('CREATE TABLE t (a INT COLUMN_FORMAT DYNAMIC)')->toString());
38 }
39}
40