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

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Alter;
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\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Alter\DropIndex;
13
14#[CoversClass(DropIndex::class)]
15#[Medium]
16final class DropIndexTest extends TestCase
17{
18    public function testDeriveStatementResolvesTheTableAndChecksTheOptions(): void
19    {
20        $drop = (new Semantics())->inspect('DROP INDEX i ON t ALGORITHM = FAST', []);
21
22        self::assertSame(['Relation t does not exist.', 'FAST is not an ALGORITHM the server knows.'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $drop->facts->diagnostics));
23    }
24
25    public function testRenderWritesTheOptionsInOrder(): void
26    {
27        self::assertSame('DROP INDEX `PRIMARY` ON db.t LOCK = shared ALGORITHM = DEFAULT', (new Semantics())->inspect('drop index `PRIMARY` on db.t lock shared algorithm default')->toString());
28    }
29}
30