|
4 | 4 |
|
5 | 5 | namespace staabm\PHPStanDba\Tests; |
6 | 6 |
|
| 7 | +use Composer\InstalledVersions; |
| 8 | +use Composer\Semver\VersionParser; |
7 | 9 | use PHPStan\Rules\Rule; |
8 | 10 | use PHPStan\Testing\RuleTestCase; |
9 | 11 | use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector; |
@@ -302,6 +304,46 @@ public function testSyntaxErrorInQueryRule(): void |
302 | 304 | $this->analyse([__DIR__ . '/data/syntax-error-in-query-method.php'], $expected); |
303 | 305 | } |
304 | 306 |
|
| 307 | + public function testSyntaxErrorInQueryRuleForDoctrineDbal3(): void |
| 308 | + { |
| 309 | + if (! InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '3.*')) { |
| 310 | + self::markTestSkipped('Doctrine DBAL 3.x test only.'); |
| 311 | + } |
| 312 | + |
| 313 | + if (MysqliQueryReflector::NAME === getenv('DBA_REFLECTOR')) { |
| 314 | + $expected = [ |
| 315 | + [ |
| 316 | + "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).", |
| 317 | + 12, |
| 318 | + ], |
| 319 | + ]; |
| 320 | + } elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) { |
| 321 | + if ('mariadb' === $_ENV['DBA_PLATFORM']) { |
| 322 | + self::markTestSkipped("We don't test all variants of expectations for all drivers"); |
| 323 | + } |
| 324 | + |
| 325 | + $expected = [ |
| 326 | + [ |
| 327 | + "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).", |
| 328 | + 12, |
| 329 | + ], |
| 330 | + ]; |
| 331 | + } elseif (PdoPgSqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) { |
| 332 | + $expected = [ |
| 333 | + [ |
| 334 | + 'Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1" |
| 335 | +LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT... |
| 336 | + ^ (42601).', |
| 337 | + 12, |
| 338 | + ], |
| 339 | + ]; |
| 340 | + } else { |
| 341 | + throw new \RuntimeException('Unsupported DBA_REFLECTOR ' . getenv('DBA_REFLECTOR')); |
| 342 | + } |
| 343 | + |
| 344 | + $this->analyse([__DIR__ . '/data/syntax-error-in-query-method-dbal3.php'], $expected); |
| 345 | + } |
| 346 | + |
305 | 347 | public function testMysqliExecuteQuery(): void |
306 | 348 | { |
307 | 349 | if (\PHP_VERSION_ID < 80200) { |
|
0 commit comments