File tree Expand file tree Collapse file tree 2 files changed +102
-0
lines changed
tests/Rules/Doctrine/DBAL Expand file tree Collapse file tree 2 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace PHPStan \Rules \Doctrine \DBAL ;
44
5+ use Composer \InstalledVersions ;
6+ use Composer \Semver \VersionParser ;
57use PHPStan \Rules \Rule ;
68use PHPStan \Testing \RuleTestCase ;
79
1113final 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 number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments