packages/sql-semantics-mysql/tests/Unit/Rules/Utility/ShowTargetsTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Utility;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Rules\Utility\ShowTargets;
11use SqlSemantics\Platform\MySql\Semantics;
12
13#[CoversClass(ShowTargets::class)]
14#[Medium]
15final class ShowTargetsTest extends TestCase
16{
17    public function testDeriveResolvesTheTableWithItsColumns(): void
18    {
19        $semantics = new Semantics();
20        $table = $semantics->inspect('CREATE TABLE t (a INT, b INT)');
21        $show = $semantics->inspect('SHOW COLUMNS FROM t', [$table]);
22        self::assertInstanceOf(\SqlSemantics\Platform\MySql\Statement\Utility\Show\Schema\ShowColumns::class, $show->statement);
23        self::assertCount(2, $show->facts->relation($show->statement->table)->shape->slots);
24        $missing = $semantics->inspect('SHOW COLUMNS FROM t FROM other', [$table]);
25        self::assertSame('Relation t does not exist.', $missing->facts->diagnostics[0]->message());
26    }
27}
28