packages/sql-semantics-mysql/tests/Unit/Statement/Server/KeyCache/LoadIndexTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Server\KeyCache;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Reference\Table\DeclaredTable;
11use SqlSemantics\Platform\MySql\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Server\KeyCache\LoadIndex;
13
14#[CoversClass(LoadIndex::class)]
15#[Medium]
16final class LoadIndexTest extends TestCase
17{
18    public function testRenderWritesTheTables(): void
19    {
20        self::assertSame('LOAD INDEX INTO CACHE t, u', (new Semantics())->analyze('load index into cache t, u')->toString());
21    }
22
23    public function testDeriveStatementResolvesEachTable(): void
24    {
25        $semantics = new Semantics();
26        $table = $semantics->analyze('CREATE TABLE t (a INT, b INT)');
27        $operation = $semantics->analyze('LOAD INDEX INTO CACHE t', [$table]);
28        self::assertInstanceOf(LoadIndex::class, $operation->statement);
29
30        self::assertInstanceOf(DeclaredTable::class, $operation->facts->relation($operation->statement->tables[0])->table);
31    }
32}
33