packages/sql-semantics-mysql/tests/Unit/Lowering/Server/Transaction/LockRuleTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lowering\Server\Transaction;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Lowering\Server\Transaction\LockRule;
11use SqlSemantics\Platform\MySql\Semantics;
12
13#[CoversClass(LockRule::class)]
14#[Medium]
15final class LockRuleTest extends TestCase
16{
17    public function testStatementLowersInstanceLocks(): void
18    {
19        self::assertSame('UNLOCK INSTANCE', (new Semantics('mysql-8.0.44'))->analyze('unlock instance')->toString());
20    }
21
22    public function testTablesLowersTheList(): void
23    {
24        self::assertSame('LOCK TABLES t WRITE, u READ', (new Semantics())->analyze('lock tables t write, u read')->toString());
25    }
26
27    public function testLockLowersTheAlias(): void
28    {
29        self::assertSame('LOCK TABLES t AS `x y` READ LOCAL', (new Semantics('mysql-5.6.51'))->analyze('lock table t as `x y` read local')->toString());
30    }
31
32    public function testUnlockLowersTableAndTables(): void
33    {
34        self::assertSame('UNLOCK TABLES', (new Semantics())->analyze('unlock table')->toString());
35    }
36}
37