Skip to content

Commit

Permalink
Deal with older dbal versiosn
Browse files Browse the repository at this point in the history
  • Loading branch information
BackEndTea committed Feb 9, 2024
1 parent 462d7c1 commit ad4318e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"doctrine/common": "^2.7 || ^3.0",
"doctrine/dbal": "^2.13.8 || ^3.3.3",
"doctrine/lexer": "^2.0 || ^3.0",
"doctrine/mongodb-odm": "^1.3 || ^2.4.3",
"doctrine/orm": "^2.16.0",
"doctrine/persistence": "^2.2.1 || ^3.2",
"gedmo/doctrine-extensions": "^3.8",
Expand All @@ -33,7 +32,7 @@
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-phpunit": "^1.3.13",
"phpstan/phpstan-strict-rules": "^1.5.1",
"phpunit/phpunit": "^9.6.16",
"phpunit/phpunit": "^8.5.31",
"ramsey/uuid": "^4.2",
"symfony/cache": "^5.4"
},
Expand Down
38 changes: 38 additions & 0 deletions tests/Rules/Doctrine/DBAL/ArrayParameterTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPStan\Rules\Doctrine\DBAL;

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;

Expand All @@ -11,8 +13,44 @@
final class ArrayParameterTypeRuleTest extends RuleTestCase
{

public function testRuleOlderDbal(): void
{
if(InstalledVersions::satisfies(
new VersionParser(),
'doctrine/dbal',
'^3.6 || ^4.0'
)) {
self::markTestSkipped('Test requires dbal 2.');
}
$this->analyse([__DIR__ . '/data/connection_dbal2.php'], [
[
'Parameter at 0 is an array, but is not hinted as such to doctrine.',
10,
],
[
"Parameter at 'a' is an array, but is not hinted as such to doctrine.",
19,
],
[
"Parameter at 'a' is an array, but is not hinted as such to doctrine.",
28,
],
[
"Parameter at 'a' is an array, but is not hinted as such to doctrine.",
39,
],
]);
}

public function testRule(): void
{
if(InstalledVersions::satisfies(
new VersionParser(),
'doctrine/dbal',
'<3.6'
)) {
self::markTestSkipped('Test requires dbal 3 or 4.');
}
$this->analyse([__DIR__ . '/data/connection.php'], [
[
'Parameter at 0 is an array, but is not hinted as such to doctrine.',
Expand Down
64 changes: 64 additions & 0 deletions tests/Rules/Doctrine/DBAL/data/connection_dbal2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace PHPStan\Rules\Doctrine\DBAL;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;

function check(Connection $connection, array $data) {

$connection->executeQuery(
'SELECT 1 FROM table WHERE a IN (?) AND b = ?',
[

$data,
3
]
);

$connection->fetchOne(
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
[

'a' => $data,
'b' => 3
]
);

$connection->fetchOne(
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
[
'a' => $data,
'b' => 3
],
[
'b' => ParameterType::INTEGER,
]
);

$connection->fetchOne(
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
[
'a' => $data,
'b' => 3
],
[
'a' => ParameterType::INTEGER,
'b' => ParameterType::INTEGER,
]
);


$connection->fetchOne(
'SELECT 1 FROM table WHERE a IN (:a) AND b = :b',
[
'a' => $data,
'b' => 3
],
[
'a' => Connection::PARAM_INT_ARRAY,
'b' => ParameterType::INTEGER,
]
);

}

0 comments on commit ad4318e

Please sign in to comment.