Skip to content

Commit cb766c5

Browse files
staabmclxmstaab
andauthored
cover SyntaxErrorInPreparedStatementMethodRuleReflectorTest on pgsql (#386)
Co-authored-by: Markus Staab <[email protected]>
1 parent ad5da7c commit cb766c5

File tree

3 files changed

+199
-162
lines changed

3 files changed

+199
-162
lines changed

tests/rules/SyntaxErrorInPreparedStatementMethodRuleMysqliReflectorTest.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/rules/SyntaxErrorInPreparedStatementMethodRulePdoReflectorTest.php

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
3+
namespace staabm\PHPStanDba\Tests;
4+
5+
use PHPStan\Rules\Rule;
6+
use PHPStan\Testing\RuleTestCase;
7+
use staabm\PHPStanDba\Rules\SyntaxErrorInPreparedStatementMethodRule;
8+
9+
/**
10+
* @extends RuleTestCase<SyntaxErrorInPreparedStatementMethodRule>
11+
*/
12+
class SyntaxErrorInPreparedStatementMethodRuleReflectorTest extends RuleTestCase
13+
{
14+
protected function getRule(): Rule
15+
{
16+
return self::getContainer()->getByType(SyntaxErrorInPreparedStatementMethodRule::class);
17+
}
18+
19+
public static function getAdditionalConfigFiles(): array
20+
{
21+
return [
22+
__DIR__.'/config/syntax-error-in-prepared-statement.neon',
23+
];
24+
}
25+
26+
public function testSyntaxErrorInQueryRule(): void
27+
{
28+
if ('mysqli' === getenv('DBA_REFLECTOR')) {
29+
$expectedErrors = [
30+
[
31+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
32+
12,
33+
],
34+
[
35+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
36+
17,
37+
],
38+
[
39+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'FROM ada LIMIT 0' at line 3 (1064).",
40+
22,
41+
],
42+
[
43+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'FROM ada LIMIT 0' at line 3 (1064).",
44+
29,
45+
],
46+
[
47+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
48+
105,
49+
],
50+
[
51+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
52+
106,
53+
],
54+
[
55+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
56+
107,
57+
],
58+
[
59+
"Query error: Unknown column 'asdsa' in 'where clause' (1054).",
60+
122,
61+
],
62+
[
63+
'Value :gesperrt is given, but the query does not contain this placeholder.',
64+
137,
65+
],
66+
[
67+
'Query expects placeholder :name, but it is missing from values given.',
68+
307,
69+
],
70+
[
71+
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'gesperrt freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
72+
319,
73+
],
74+
];
75+
} elseif ('pdo-pgsql' === getenv('DBA_REFLECTOR')) {
76+
$expectedErrors = [
77+
[
78+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
79+
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
80+
^ (42601).',
81+
12,
82+
],
83+
[
84+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
85+
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
86+
^ (42601).',
87+
17,
88+
],
89+
[
90+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "FROM"
91+
LINE 3: FROM ada LIMIT 0
92+
^ (42601).',
93+
22,
94+
],
95+
[
96+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "FROM"
97+
LINE 3: FROM ada LIMIT 0
98+
^ (42601).',
99+
29,
100+
],
101+
[
102+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
103+
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
104+
^ (42601).',
105+
105,
106+
],
107+
[
108+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
109+
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
110+
^ (42601).',
111+
106,
112+
],
113+
[
114+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
115+
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
116+
^ (42601).',
117+
107,
118+
],
119+
[
120+
'Query error: SQLSTATE[42703]: Undefined column: 7 ERROR: column "asdsa" does not exist
121+
LINE 1: ...mail, adaid, gesperrt, freigabe1u1 FROM ada WHERE asdsa=\'1\' ...
122+
^ (42703).',
123+
122,
124+
],
125+
[
126+
'Value :gesperrt is given, but the query does not contain this placeholder.
127+
162: Query error: SQLSTATE[42703]: Undefined column: 7 ERROR: column ":gesperrt%" does not exist
128+
LINE 1: SELECT adaid FROM ada WHERE email LIKE ":gesperrt%" LIMIT 0
129+
^
130+
HINT: Perhaps you meant to reference the column "ada.gesperrt". (42703).',
131+
137,
132+
],
133+
[
134+
'Query expects placeholder :name, but it is missing from values given.',
135+
307,
136+
],
137+
[
138+
'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "gesperrt"
139+
LINE 1: SELECT email adaid gesperrt freigabe1u1 FROM ada LIMIT 0
140+
^ (42601).',
141+
319,
142+
],
143+
];
144+
} elseif ('pdo-mysql' === getenv('DBA_REFLECTOR')) {
145+
$expectedErrors = [
146+
[
147+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
148+
12,
149+
],
150+
[
151+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
152+
17,
153+
],
154+
[
155+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'FROM ada LIMIT 0' at line 3 (42000).",
156+
22,
157+
],
158+
[
159+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'FROM ada LIMIT 0' at line 3 (42000).",
160+
29,
161+
],
162+
[
163+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
164+
105,
165+
],
166+
[
167+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
168+
106,
169+
],
170+
[
171+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
172+
107,
173+
],
174+
[
175+
"Query error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'asdsa' in 'where clause' (42S22).",
176+
122,
177+
],
178+
[
179+
'Value :gesperrt is given, but the query does not contain this placeholder.',
180+
137,
181+
],
182+
[
183+
'Query expects placeholder :name, but it is missing from values given.',
184+
307,
185+
],
186+
[
187+
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'gesperrt freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
188+
319,
189+
],
190+
];
191+
} else {
192+
throw new \RuntimeException('Unsupported DBA_REFLECTOR '.getenv('DBA_REFLECTOR'));
193+
}
194+
195+
require_once __DIR__.'/data/syntax-error-in-prepared-statement.php';
196+
197+
$this->analyse([__DIR__.'/data/syntax-error-in-prepared-statement.php'], $expectedErrors);
198+
}
199+
}

0 commit comments

Comments
 (0)