packages/sql-semantics-mysql/tests/Unit/Statement/Routine/Problem/ProgramRuleTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Routine\Problem;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Statement\Routine\Problem\ProgramRule;
11
12#[CoversClass(ProgramRule::class)]
13#[Small]
14final class ProgramRuleTest extends TestCase
15{
16 public function testCasesHoldTheirMessagePatterns(): void
17 {
18 self::assertSame([
19 'Duplicate parameter: %s',
20 'Duplicate variable: %s',
21 'Duplicate condition: %s',
22 'Duplicate cursor: %s',
23 'Redefining label %s',
24 'End-label %s without match',
25 'LEAVE with no matching label: %s',
26 'ITERATE with no matching label: %s',
27 'Undefined CONDITION: %s',
28 'Undefined CURSOR: %s',
29 'Undeclared variable: %s',
30 'RETURN is only allowed in a FUNCTION',
31 'No RETURN found in FUNCTION %s',
32 'Variable or condition declaration after cursor or handler declaration',
33 'Cursor declaration after handler declaration',
34 "Bad SQLSTATE: '%s'",
35 "Incorrect CONDITION value: '0'",
36 'Duplicate handler declared in the same block',
37 'SIGNAL/RESIGNAL can only use a CONDITION defined with SQLSTATE',
38 "Duplicate condition information item '%s'",
39 '%s is not allowed in stored procedures',
40 "Can't create a %s from within another stored routine",
41 "Can't drop or alter a %s from within another stored routine",
42 'Recursion of EVENT DDL statements is forbidden when body is present',
43 'Not allowed to return a result set from a %s',
44 'Explicit or implicit commit is not allowed in stored function or trigger.',
45 '%s is not allowed in stored function or trigger',
46 'Updating of OLD row is not allowed in trigger',
47 'Updating of NEW row is not allowed in after trigger',
48 'There is no NEW row in on DELETE trigger',
49 ], array_map(static fn (ProgramRule $rule): string => $rule->value, ProgramRule::cases()));
50 }
51
52 public function testCasesNameTheCasesOfTheServerErrors(): void
53 {
54 self::assertSame([
55 'DuplicateParameter',
56 'DuplicateVariable',
57 'DuplicateCondition',
58 'DuplicateCursor',
59 'RedefinedLabel',
60 'EndLabelMismatch',
61 'LeaveWithoutLabel',
62 'IterateWithoutLabel',
63 'UndefinedCondition',
64 'UndefinedCursor',
65 'UndeclaredVariable',
66 'ReturnOutsideFunction',
67 'MissingReturn',
68 'DeclarationAfterCursorOrHandler',
69 'CursorAfterHandler',
70 'BadSqlState',
71 'ZeroErrorCode',
72 'DuplicateHandler',
73 'SignalConditionKind',
74 'DuplicateSignalItem',
75 'BadStatement',
76 'RecursiveCreate',
77 'NestedAlterOrDrop',
78 'EventRecursion',
79 'ResultSet',
80 'CommitInFunction',
81 'FunctionStatement',
82 'OldRowUpdate',
83 'AfterRowUpdate',
84 'NoNewRow',
85 ], array_map(static fn (ProgramRule $rule): string => $rule->name, ProgramRule::cases()));
86 }
87}
88