packages/sql-semantics-mysql/tests/Unit/Statement/Utility/Show/Server/ShowVariablesTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Utility\Show\Server;
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\Server\ShowVariables;
12
13#[CoversClass(ShowVariables::class)]
14#[Medium]
15final class ShowVariablesTest extends TestCase
16{
17 public function testDeriveStatementResolvesTheCondition(): void
18 {
19 $show = (new Semantics('mysql-5.7.44'))->analyze('SHOW GLOBAL VARIABLES WHERE Value IS NULL');
20 self::assertInstanceOf(ShowVariables::class, $show->statement);
21 self::assertSame([], $show->facts->diagnostics);
22 self::assertSame(\SqlSemantics\Platform\MySql\Statement\Variable\VariableScope::Global, $show->statement->scope);
23 }
24
25 public function testDeriveRelationShapesTheResultColumns(): void
26 {
27 $show = (new Semantics('mysql-5.7.44'))->analyze('SHOW GLOBAL VARIABLES WHERE Value IS NULL');
28 self::assertInstanceOf(ShowVariables::class, $show->statement);
29 self::assertSame('Value', $show->facts->relation($show->statement)->shape->slots[1]->name?->value);
30 }
31
32 public function testRenderWritesTheStatement(): void
33 {
34 self::assertSame('SHOW GLOBAL VARIABLES WHERE `Value` IS NULL', (new Semantics('mysql-5.7.44'))->analyze('SHOW GLOBAL VARIABLES WHERE Value IS NULL')->toString());
35 }
36}
37