packages/sql-semantics-mysql/tests/Unit/Statement/Partition/Method/ColumnsMethodTest.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\Semantics;
11use SqlSemantics\Platform\MySql\Statement\Partition\Method\ColumnsMethod;
12
13#[CoversClass(ColumnsMethod::class)]
14#[Medium]
15final class ColumnsMethodTest extends TestCase
16{
17    public function testDeriveMethodReportsAColumnTheTableDoesNotHave(): void
18    {
19        $semantics = new Semantics();
20        $table = $semantics->inspect('CREATE TABLE t (a INT)');
21
22        self::assertSame('Column b does not exist in the table.', $semantics->inspect('ALTER TABLE t PARTITION BY RANGE COLUMNS (a, b) (PARTITION p VALUES LESS THAN (1, 2))', [$table])->facts->diagnostics[0]->message());
23    }
24
25    public function testRenderWritesTheColumns(): void
26    {
27        self::assertSame('ALTER TABLE t PARTITION BY LIST COLUMNS (a, b)', (new Semantics())->inspect('ALTER TABLE t PARTITION BY LIST COLUMNS (a, b)')->toString());
28    }
29}
30