Skip to content

Commit 776dcf6

Browse files
author
Bartłomiej Nowak
committed
SyntaxErrorInQueryMethodRuleTest test-cases for doctrine dbal 3 only
1 parent 1de3850 commit 776dcf6

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/rules/SyntaxErrorInQueryMethodRuleTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace staabm\PHPStanDba\Tests;
66

7+
use Composer\InstalledVersions;
8+
use Composer\Semver\VersionParser;
79
use PHPStan\Rules\Rule;
810
use PHPStan\Testing\RuleTestCase;
911
use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector;
@@ -302,6 +304,46 @@ public function testSyntaxErrorInQueryRule(): void
302304
$this->analyse([__DIR__ . '/data/syntax-error-in-query-method.php'], $expected);
303305
}
304306

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+
305347
public function testMysqliExecuteQuery(): void
306348
{
307349
if (\PHP_VERSION_ID < 80200) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace SyntaxErrorInQueryMethodDbal3RuleTest;
4+
5+
use PDO;
6+
7+
class Foo
8+
{
9+
public function syntaxErrorDoctrineDbal(\Doctrine\DBAL\Connection $conn)
10+
{
11+
$sql = 'SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada';
12+
$conn->query($sql);
13+
}
14+
15+
public function noErrorOnQueriesContainingPlaceholders(\Doctrine\DBAL\Connection $conn)
16+
{
17+
// errors in this scenario are reported by SyntaxErrorInPreparedStatementMethodRule only
18+
$conn->query('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid=?');
19+
}
20+
}

0 commit comments

Comments
 (0)