packages/sql-semantics-mysql/tests/Unit/Statement/Alter/Modifier/LockOptionTest.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\LockOption;
12
13#[CoversClass(LockOption::class)]
14#[Medium]
15final class LockOptionTest extends TestCase
16{
17    public function testDeriveOptionReportsALockTheReleaseDoesNotKnow(): void
18    {
19        self::assertSame('DEFAULT is not a LOCK the server knows.', (new Semantics())->inspect('DROP INDEX i ON t LOCK = `DEFAULT`')->facts->diagnostics[0]->message());
20    }
21
22    public function testDeriveCommandChecksTheLock(): void
23    {
24        self::assertSame([], (new Semantics('mysql-5.6.51'))->inspect('ALTER TABLE t LOCK = `default`')->facts->diagnostics);
25    }
26
27    public function testRenderWritesTheLockOrDefault(): void
28    {
29        self::assertSame('ALTER TABLE t LOCK = DEFAULT, LOCK = EXCLUSIVE', (new Semantics())->inspect('ALTER TABLE t LOCK DEFAULT, LOCK EXCLUSIVE')->toString());
30    }
31}
32