packages/sql-semantics-postgres/tests/Unit/Statement/Table/Partition/PartitionSpecTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table\Partition;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Table\Partition\PartitionSpec::class)]
12#[Medium]
13final class PartitionSpecTest extends TestCase
14{
15    public function testDeriveClauseReportsAnUnknownStrategy(): void
16    {
17        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
18        $statement = $semantics->inspect('CREATE TABLE n (a int) PARTITION BY tree (a)', []);
19        self::assertSame([
20          0 => 'unrecognized partitioning strategy "tree"',
21        ], array_map(static fn ($problem): string => $problem->message(), $statement->facts->diagnostics));
22    }
23
24    public function testRenderWritesTheClauseAsWritten(): void
25    {
26        $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
27        $statement = $semantics->inspect('CREATE TABLE n (a int) PARTITION BY "RANGE" (a)', []);
28        self::assertSame('CREATE TABLE n (a INT) PARTITION BY "RANGE" (a)', $statement->toString());
29    }
30}
31