packages/sql-semantics-postgres/tests/Unit/Statement/Routine/Option/ParallelSafetyTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Routine\Option;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Construction\Derivation;
11use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
12use SqlSemantics\Platform\PostgreSql\Model\Contract\LanguageProfile;
13use SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical;
14use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
15use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
16use SqlSemantics\Platform\PostgreSql\Platform;
17use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
18use SqlSemantics\Platform\PostgreSql\Statement\Routine\Option\ParallelSafety;
19
20#[CoversClass(ParallelSafety::class)]
21#[Small]
22final class ParallelSafetyTest extends TestCase
23{
24    public function testValidAcceptsTheThreeLevels(): void
25    {
26        self::assertSame([true, true, false], [(new ParallelSafety(new Name('restricted')))->valid(), (new ParallelSafety(new Name('unsafe')))->valid(), (new ParallelSafety(new Name('Safe')))->valid()]);
27    }
28
29    public function testAlterableIsTrue(): void
30    {
31        self::assertTrue((new ParallelSafety(new Name('safe')))->alterable());
32    }
33
34    public function testSettingIsParallel(): void
35    {
36        self::assertSame('parallel', (new ParallelSafety(new Name('safe')))->setting());
37    }
38
39    public function testDeriveClauseRecordsNothing(): void
40    {
41        $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
42        (new ParallelSafety(new Name('bogus')))->deriveClause($derivation, $derivation->environment());
43        self::assertSame([], $derivation->facts()->diagnostics);
44    }
45
46    public function testRenderWritesTheLevel(): void
47    {
48        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
49        (new ParallelSafety(new Name('safe')))->render($out);
50        self::assertSame('PARALLEL safe', (new Lexical())->join($out->pieces()));
51    }
52}
53