packages/sql-semantics-mysql/tests/Unit/Statement/Table/Column/SridAttributeTest.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\SridAttribute;
13use SqlSemantics\Platform\MySql\Statement\Table\CreateTable;
14
15#[CoversClass(SridAttribute::class)]
16#[Medium]
17final class SridAttributeTest extends TestCase
18{
19    public function testDeriveAttributeDerivesNothing(): void
20    {
21        $create = (new Semantics())->analyze('CREATE TABLE t (g POINT SRID 4326)');
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(SridAttribute::class, $attribute);
31        self::assertSame('4326', $attribute->srid->text);
32    }
33
34    public function testRenderWritesTheAttribute(): void
35    {
36        self::assertSame('CREATE TABLE t (g POINT SRID 4326)', (new Semantics())->analyze('CREATE TABLE t (g POINT SRID 4326)')->toString());
37    }
38}
39