packages/sql-faker/tests/Unit/Generation/Exception/GenerationExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\Generation\Exception;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use SqlFaker\Generation\Exception\GenerationException;
10
11#[CoversClass(GenerationException::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFaker\Generation\Derivation\CompletionCosts::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFaker\Generation\Derivation\DerivationNode::class)]
14final class GenerationExceptionTest extends TestCase
15{
16    public function testDerivationLimitExceededReportsTheBudget(): void
17    {
18        self::assertSame(
19            'Exceeded derivation limit while generating SQL.',
20            GenerationException::derivationLimitExceeded()->getMessage(),
21        );
22    }
23
24    public function testUnknownRuleNamesTheMissingRule(): void
25    {
26        self::assertSame(
27            'Unknown grammar rule: opt_where',
28            GenerationException::unknownRule('opt_where')->getMessage(),
29        );
30    }
31
32    public function testRuleHasNoAlternativesNamesTheEmptyRule(): void
33    {
34        self::assertSame(
35            "Production rule 'statement' has no alternatives.",
36            GenerationException::ruleHasNoAlternatives('statement')->getMessage(),
37        );
38    }
39
40    public function testNoRealizableAlternativeNamesTheRule(): void
41    {
42        self::assertSame(
43            'Grammar rule has no lexically realizable alternative: infinite',
44            GenerationException::noRealizableAlternative('infinite')->getMessage(),
45        );
46    }
47
48    public function testNoAlternativeMatchingPlanNamesTheRule(): void
49    {
50        self::assertSame(
51            'Grammar rule has no alternative matching the generation plan: opt_values',
52            GenerationException::noAlternativeMatchingPlan('opt_values')->getMessage(),
53        );
54    }
55
56    public function testStartRuleCannotProduceOutputNamesTheStartRule(): void
57    {
58        self::assertSame(
59            'Generation plan requires non-empty output, but the start rule cannot produce it: statement',
60            GenerationException::startRuleCannotProduceOutput('statement')->getMessage(),
61        );
62    }
63
64    public function testPlanRequiresNonEmptyOutputNamesTheDialect(): void
65    {
66        self::assertSame(
67            'MySQL generation plan requires non-empty output.',
68            GenerationException::planRequiresNonEmptyOutput('MySQL')->getMessage(),
69        );
70    }
71
72    public function testLexicalRealizationFailedNamesTheDialect(): void
73    {
74        self::assertSame(
75            'SQLite lexical realization failed.',
76            GenerationException::lexicalRealizationFailed('SQLite')->getMessage(),
77        );
78    }
79}
80