packages/sql-semantics-mysql/tests/Unit/Statement/Alter/Command/SetTableOptionsTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Alter\Command;
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\Alter\AlterTable;
12use SqlSemantics\Platform\MySql\Statement\Alter\Command\SetTableOptions;
13
14#[CoversClass(SetTableOptions::class)]
15#[Medium]
16final class SetTableOptionsTest extends TestCase
17{
18    public function testDeriveCommandDerivesTheOptions(): void
19    {
20        $semantics = new Semantics();
21        $table = $semantics->analyze('CREATE TABLE t (a INT, b INT)');
22        self::assertSame([], $semantics->analyze('ALTER TABLE t ENGINE = InnoDB', [$table])->facts->diagnostics);
23    }
24
25    public function testRenderWritesTheRunsApart(): void
26    {
27        $alter = (new Semantics())->analyze("ALTER TABLE t ENGINE = InnoDB COMMENT = 'x', AUTO_INCREMENT = 5");
28
29        self::assertInstanceOf(AlterTable::class, $alter->statement);
30        self::assertCount(2, $alter->statement->commands);
31    }
32}
33