packages/sql-semantics-mysql/tests/Unit/Statement/Alter/Modifier/AlgorithmOptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Alter\Modifier;
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\Modifier\AlgorithmOption;
12
13#[CoversClass(AlgorithmOption::class)]
14#[Medium]
15final class AlgorithmOptionTest extends TestCase
16{
17    public function testDeriveOptionReportsAnAlgorithmTheReleaseDoesNotKnow(): void
18    {
19        self::assertSame('INSTANT is not an ALGORITHM the server knows.', (new Semantics('mysql-5.7.44'))->inspect('DROP INDEX i ON t ALGORITHM = INSTANT')->facts->diagnostics[0]->message());
20        self::assertSame([], (new Semantics())->inspect('DROP INDEX i ON t ALGORITHM = instant')->facts->diagnostics);
21    }
22
23    public function testDeriveCommandChecksTheAlgorithm(): void
24    {
25        self::assertSame('NOCOPY is not an ALGORITHM the server knows.', (new Semantics())->inspect('ALTER TABLE t ALGORITHM = NOCOPY')->facts->diagnostics[0]->message());
26    }
27
28    public function testRenderWritesTheAlgorithmOrDefault(): void
29    {
30        self::assertSame('ALTER TABLE t ALGORITHM = DEFAULT, ALGORITHM = INPLACE', (new Semantics())->inspect('ALTER TABLE t ALGORITHM DEFAULT, ALGORITHM INPLACE')->toString());
31    }
32}
33