Skip to content

Commit ad4318e

Browse files
committed
Deal with older dbal versiosn
1 parent 462d7c1 commit ad4318e

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"doctrine/common": "^2.7 || ^3.0",
2525
"doctrine/dbal": "^2.13.8 || ^3.3.3",
2626
"doctrine/lexer": "^2.0 || ^3.0",
27-
"doctrine/mongodb-odm": "^1.3 || ^2.4.3",
2827
"doctrine/orm": "^2.16.0",
2928
"doctrine/persistence": "^2.2.1 || ^3.2",
3029
"gedmo/doctrine-extensions": "^3.8",
@@ -33,7 +32,7 @@
3332
"php-parallel-lint/php-parallel-lint": "^1.2",
3433
"phpstan/phpstan-phpunit": "^1.3.13",
3534
"phpstan/phpstan-strict-rules": "^1.5.1",
36-
"phpunit/phpunit": "^9.6.16",
35+
"phpunit/phpunit": "^8.5.31",
3736
"ramsey/uuid": "^4.2",
3837
"symfony/cache": "^5.4"
3938
},

tests/Rules/Doctrine/DBAL/ArrayParameterTypeRuleTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPStan\Rules\Doctrine\DBAL;
44

5+
use Composer\InstalledVersions;
6+
use Composer\Semver\VersionParser;
57
use PHPStan\Rules\Rule;
68
use PHPStan\Testing\RuleTestCase;
79

@@ -11,8 +13,44 @@
1113
final class ArrayParameterTypeRuleTest extends RuleTestCase
1214
{
1315

16+
public function testRuleOlderDbal(): void
17+
{
18+
if(InstalledVersions::satisfies(
19+
new VersionParser(),
20+
'doctrine/dbal',
21+
'^3.6 || ^4.0'
22+
)) {
23+
self::markTestSkipped('Test requires dbal 2.');
24+
}
25+
$this->analyse([__DIR__ . '/data/connection_dbal2.php'], [
26+
[
27+
'Parameter at 0 is an array, but is not hinted as such to doctrine.',
28+
10,
29+
],
30+
[
31+
"Parameter at 'a' is an array, but is not hinted as such to doctrine.",
32+
19,
33+
],
34+
[
35+
"Parameter at 'a' is an array, but is not hinted as such to doctrine.",
36+
28,
37+
],
38+
[
39+
"Parameter at 'a' is an array, but is not hinted as such to doctrine.",
40+
39,
41+
],
42+
]);
43+
}
44+
1445
public function testRule(): void
1546
{
47+
if(InstalledVersions::satisfies(
48+
new VersionParser(),
49+
'doctrine/dbal',
50+
'<3.6'
51+
)) {
52+
self::markTestSkipped('Test requires dbal 3 or 4.');
53+
}
1654
$this->analyse([__DIR__ . '/data/connection.php'], [
1755
[
1856
'Parameter at 0 is an array, but is not hinted as such to doctrine.',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace PHPStan\Rules\Doctrine\DBAL;
4+
5+
use Doctrine\DBAL\Connection;
6+
use Doctrine\DBAL\ParameterType;
7+
8+
function check(Connection $connection, array $data) {
9+
10+
$connection->executeQuery(
11+
'SELECT 1 FROM table WHERE a IN (?) AND b = ?',
12+
[
13+
14+
$data,
15+
3
16+
]
17+
);
18+
19+
$connection->fetchOne(
20+
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
21+
[
22+
23+
'a' => $data,
24+
'b' => 3
25+
]
26+
);
27+
28+
$connection->fetchOne(
29+
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
30+
[
31+
'a' => $data,
32+
'b' => 3
33+
],
34+
[
35+
'b' => ParameterType::INTEGER,
36+
]
37+
);
38+
39+
$connection->fetchOne(
40+
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
41+
[
42+
'a' => $data,
43+
'b' => 3
44+
],
45+
[
46+
'a' => ParameterType::INTEGER,
47+
'b' => ParameterType::INTEGER,
48+
]
49+
);
50+
51+
52+
$connection->fetchOne(
53+
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
54+
[
55+
'a' => $data,
56+
'b' => 3
57+
],
58+
[
59+
'a' => Connection::PARAM_INT_ARRAY,
60+
'b' => ParameterType::INTEGER,
61+
]
62+
);
63+
64+
}

0 commit comments

Comments
 (0)