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

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Partition;
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\PartitionClause;
13
14#[CoversClass(PartitionClause::class)]
15#[Medium]
16final class PartitionClauseTest extends TestCase
17{
18    public function testDerivePartitioningDerivesTheMethodAndTheValues(): void
19    {
20        $semantics = new Semantics();
21        $table = $semantics->inspect('CREATE TABLE t (a INT)');
22        $alter = $semantics->inspect('ALTER TABLE t PARTITION BY RANGE (b) (PARTITION p VALUES LESS THAN (c))', [$table]);
23
24        self::assertSame(['Column b does not exist.', 'Column c does not exist.'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $alter->facts->diagnostics));
25    }
26
27    public function testRenderWritesTheCountsAndTheDefinitions(): void
28    {
29        self::assertSame('ALTER TABLE t PARTITION BY HASH (a) PARTITIONS 2 (PARTITION p0, PARTITION p1)', (new Semantics())->inspect('ALTER TABLE t PARTITION BY HASH (a) PARTITIONS 2 (PARTITION p0, PARTITION p1)')->toString());
30    }
31}
32