packages/sql-semantics-mysql/tests/Unit/Rules/TableChange/ChoicesTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\TableChange;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
11use SqlSemantics\Platform\MySql\Rules\TableChange\Choices;
12use SqlSemantics\Platform\MySql\Semantics;
13
14#[CoversClass(Choices::class)]
15#[Medium]
16final class ChoicesTest extends TestCase
17{
18    public function testAlgorithmChecksTheAlgorithm(): void
19    {
20        $semantics = new Semantics();
21
22        self::assertSame(['SLOW is not an ALGORITHM the server knows.'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $semantics->inspect('ALTER TABLE t ALGORITHM = COPY, ALGORITHM = SLOW')->facts->diagnostics));
23    }
24
25    public function testLockChecksTheLock(): void
26    {
27        $semantics = new Semantics();
28
29        self::assertSame(['FULL is not a LOCK the server knows.'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $semantics->inspect('ALTER TABLE t LOCK = none, LOCK = FULL')->facts->diagnostics));
30    }
31
32    public function testLegacyAcceptsDefaultAsANameIn57(): void
33    {
34        $semantics = new Semantics('mysql-5.7.44');
35
36        self::assertSame([], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $semantics->inspect('ALTER TABLE t ALGORITHM = `DEFAULT`, LOCK = `DEFAULT`')->facts->diagnostics));
37    }
38
39    public function testCheckIgnoresTheKeywordDefault(): void
40    {
41        $semantics = new Semantics();
42
43        self::assertSame([], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $semantics->inspect('ALTER TABLE t ALGORITHM = DEFAULT, LOCK = DEFAULT')->facts->diagnostics));
44    }
45}
46