packages/sql-semantics-mysql/tests/Unit/Statement/Utility/Show/Server/ShowStatusTest.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\ShowStatus;
12
13#[CoversClass(ShowStatus::class)]
14#[Medium]
15final class ShowStatusTest extends TestCase
16{
17    public function testDeriveStatementResolvesTheCondition(): void
18    {
19        $show = (new Semantics('mysql-5.7.44'))->analyze('SHOW GLOBAL STATUS WHERE Value IS NULL');
20        self::assertInstanceOf(ShowStatus::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 STATUS WHERE Value IS NULL');
28        self::assertInstanceOf(ShowStatus::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 STATUS WHERE `Value` IS NULL', (new Semantics('mysql-5.7.44'))->analyze('SHOW GLOBAL STATUS WHERE Value IS NULL')->toString());
35    }
36}
37