packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Database/DatabaseOptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Database;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Database\DatabaseOption::class)]
12#[Medium]
13final class DatabaseOptionTest extends TestCase
14{
15    public function testOptionOfAnIdentifier(): void
16    {
17        $statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d is_template = true')->statement;
18        self::assertInstanceOf(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Database\CreateDatabase::class, $statement);
19        self::assertSame('is_template', $statement->options[0]->option());
20    }
21
22    public function testOptionOfAKeywordSpelling(): void
23    {
24        $statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d CONNECTION LIMIT 3')->statement;
25        self::assertInstanceOf(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Database\CreateDatabase::class, $statement);
26        self::assertSame('connection_limit', $statement->options[0]->option());
27    }
28
29    public function testRenderKeepsTheKeywordSpelling(): void
30    {
31        self::assertSame('CREATE DATABASE d WITH CONNECTION LIMIT = - 1 LOCATION = \'x\'', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d CONNECTION LIMIT -1 LOCATION \'x\'')->toString());
32    }
33
34    public function testDeriveClauseDerivesTheValue(): void
35    {
36        self::assertSame([], (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d WITH strategy = wal_log')->facts->diagnostics);
37    }
38
39    public function testRenderKeepsAnIdentifierSpelledLikeAKeywordQuoted(): void
40    {
41        self::assertSame('CREATE DATABASE d WITH "owner" = x "template" = y OWNER = z', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d "owner" x "template" = y OWNER z')->toString());
42    }
43}
44