packages/sql-semantics-mysql/tests/Unit/Statement/Partition/Method/KeyMethodTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Partition\Method;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
11use SqlSemantics\Platform\MySql\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Partition\Method\KeyMethod;
13
14#[CoversClass(KeyMethod::class)]
15#[Medium]
16final class KeyMethodTest extends TestCase
17{
18    public function testDeriveMethodReportsAColumnTheTableDoesNotHave(): void
19    {
20        $semantics = new Semantics();
21        $table = $semantics->inspect('CREATE TABLE t (a INT)');
22
23        self::assertSame(['Column q does not exist in the table.'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $semantics->inspect('ALTER TABLE t PARTITION BY KEY (a, q)', [$table])->facts->diagnostics));
24    }
25
26    public function testRenderWritesLinearAndTheAlgorithm(): void
27    {
28        self::assertSame('ALTER TABLE t PARTITION BY LINEAR KEY ALGORITHM = 2 ()', (new Semantics())->inspect('alter table t partition by linear key algorithm=2 ()')->toString());
29    }
30}
31