packages/sql-semantics-mysql/tests/Unit/Statement/Utility/Show/Schema/ShowOpenTablesTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Utility\Show\Schema;
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\Utility\Show\Schema\ShowOpenTables;
12
13#[CoversClass(ShowOpenTables::class)]
14#[Medium]
15final class ShowOpenTablesTest extends TestCase
16{
17 public function testDeriveStatementResolvesTheCondition(): void
18 {
19 $show = (new Semantics())->analyze('SHOW OPEN TABLES WHERE In_use > 0');
20 self::assertInstanceOf(ShowOpenTables::class, $show->statement);
21 self::assertSame([], $show->facts->diagnostics);
22 }
23
24 public function testDeriveRelationShapesTheResultColumns(): void
25 {
26 $show = (new Semantics())->analyze('SHOW OPEN TABLES WHERE In_use > 0');
27 self::assertInstanceOf(ShowOpenTables::class, $show->statement);
28 self::assertSame('Table', $show->facts->relation($show->statement)->shape->slots[1]->name?->value);
29 }
30
31 public function testRenderWritesTheStatement(): void
32 {
33 self::assertSame('SHOW OPEN TABLES WHERE In_use > 0', (new Semantics())->analyze('SHOW OPEN TABLES WHERE In_use > 0')->toString());
34 }
35}
36