packages/sql-semantics-mysql/tests/Unit/Rules/Server/MaintainedTablesTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Server;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\MySql\Model\Statement\Identifier\QualifiedName;
12use SqlSemantics\Platform\MySql\Rules\Server\MaintainedTables;
13use SqlSemantics\Platform\MySql\Semantics;
14use SqlSemantics\Platform\MySql\Statement\Server\Maintenance\MaintainedTable;
15use SqlSemantics\Platform\MySql\Statement\Server\Problem\NonUniqueTable;
16
17#[CoversClass(MaintainedTables::class)]
18#[Medium]
19final class MaintainedTablesTest extends TestCase
20{
21 public function testCheckedKeepsTheTables(): void
22 {
23 $tables = [new MaintainedTable(new QualifiedName(new Name('t')))];
24
25 self::assertSame($tables, (new MaintainedTables())->checked($tables));
26 }
27
28 public function testDeriveReportsATableNamedTwiceInOneDatabase(): void
29 {
30 $operation = (new Semantics())->inspect('CHECKSUM TABLE db.t, db.t');
31
32 self::assertInstanceOf(NonUniqueTable::class, $operation->facts->diagnostics[0]);
33 }
34
35 public function testDeriveAcceptsOneNameInTwoDatabases(): void
36 {
37 self::assertSame([], (new Semantics())->inspect('CHECKSUM TABLE a.t, b.t')->facts->diagnostics);
38 }
39
40 public function testRenderWritesKeywordsOptionAndTables(): void
41 {
42 self::assertSame('OPTIMIZE NO_WRITE_TO_BINLOG TABLE a.t, t', (new Semantics())->inspect('optimize local table a.t, t')->toString());
43 }
44}
45