packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Database/CreateDatabaseTest.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\CreateDatabase::class)]
12#[Medium]
13final class CreateDatabaseTest extends TestCase
14{
15 public function testRenderWritesTheOptions(): void
16 {
17 self::assertSame('CREATE DATABASE d WITH OWNER = app ENCODING = \'UTF8\'', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d WITH OWNER = app ENCODING \'UTF8\'')->toString());
18 }
19
20 public function testRenderWithoutOptions(): void
21 {
22 self::assertSame('CREATE DATABASE d', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d')->toString());
23 }
24
25 public function testDeriveStatementReportsAnUnknownOption(): void
26 {
27 self::assertSame('option "foo" not recognized', (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d foo = 1')->facts->diagnostics[0]->message());
28 }
29
30 public function testDeriveStatementAcceptsTheBuiltinLocaleOf17(): void
31 {
32 self::assertSame([], (new \SqlSemantics\Platform\PostgreSql\Semantics())->inspect('CREATE DATABASE d builtin_locale = \'C.UTF-8\'')->facts->diagnostics);
33 }
34
35 public function testDeriveStatementRejectsTheBuiltinLocaleOf16(): void
36 {
37 self::assertSame('option "builtin_locale" not recognized', (new \SqlSemantics\Platform\PostgreSql\Semantics('pg-16.6'))->inspect('CREATE DATABASE d builtin_locale = \'C.UTF-8\'')->facts->diagnostics[0]->message());
38 }
39}
40