Skip to content

Commit 34b3e80

Browse files
committed
Improve old & new dbal compatibility
1 parent 5f5284e commit 34b3e80

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

phpstan.neon

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,22 @@ parameters:
4242
-
4343
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\EntityManager'' and ''create'' will always evaluate to true\.$#'
4444
path: src/Doctrine/Mapping/ClassMetadataFactory.php
45-
reportUnmatched: false
46-
-
47-
messages:
48-
- '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Connection and ''getNativeConnection'' will always evaluate to true\.$#'
49-
- '#^Cannot call method getWrappedResourceHandle\(\) on class\-string\|object\.$#'
50-
path: tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php
51-
reportUnmatched: false
45+
5246
-
5347
message: '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Connection and ''getNativeConnection'' will always evaluate to true\.$#' # needed for older DBAL versions
5448
path: src/Type/Doctrine/Query/QueryResultTypeWalker.php
49+
5550
-
5651
messages: # needed for older DBAL versions (fails only on PHP 7.3)
5752
- '#^Class Doctrine\\DBAL\\Driver\\PgSQL\\Driver not found\.$#'
5853
- '#^Class Doctrine\\DBAL\\Driver\\SQLite3\\Driver not found\.$#'
54+
55+
-
56+
message: '#^Call to an undefined method Doctrine\\DBAL\\Connection\:\:getWrappedConnection\(\)\.$#' # dropped in DBAL 4
5957
path: src/Type/Doctrine/Query/QueryResultTypeWalker.php
58+
59+
-
60+
messages: # oldest dbal has only getSchemaManager, dbal4 has only createSchemaManager
61+
- '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Connection and ''createSchemaManager'' will always evaluate to true\.$#'
62+
- '#^Call to an undefined method Doctrine\\DBAL\\Connection\:\:getSchemaManager\(\)\.$#'
63+
path: tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

src/Type/Doctrine/Query/QueryResultTypeWalker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ public function walkSelectExpression($selectExpression): string
11221122
if ($expr instanceof TypedExpression) {
11231123
$type = TypeCombinator::intersect( // e.g. count is typed as int, but we infer int<0, max>
11241124
$type,
1125-
$this->resolveDoctrineType(DbalType::lookupName($expr->getReturnType()), null, TypeCombinator::containsNull($type))
1125+
$this->resolveDoctrineType(DbalType::getTypeRegistry()->lookupName($expr->getReturnType()), null, TypeCombinator::containsNull($type))
11261126
);
11271127
} else {
11281128
// Expressions default to Doctrine's StringType, whose

tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use function floor;
5151
use function getenv;
5252
use function in_array;
53+
use function method_exists;
5354
use function reset;
5455
use function sprintf;
5556
use function var_export;
@@ -3475,6 +3476,10 @@ private function performDriverTest(
34753476
callable $assertStringified
34763477
): void
34773478
{
3479+
if (!in_array($driver, DriverManager::getAvailableDrivers(), true)) {
3480+
return;
3481+
}
3482+
34783483
$connectionParams = [
34793484
'driver' => $driver,
34803485
'driverOptions' => self::CONNECTION_CONFIGS[$configName],
@@ -3536,8 +3541,12 @@ private function createConnection(
35363541
{
35373542
$connection = DriverManager::getConnection($connectionParams);
35383543

3544+
$schemaManager = method_exists($connection, 'createSchemaManager')
3545+
? $connection->createSchemaManager()
3546+
: $connection->getSchemaManager();
3547+
35393548
if (!isset($connectionParams['dbname'])) {
3540-
if (!in_array('foo', $connection->createSchemaManager()->listDatabases(), true)) {
3549+
if (!in_array('foo', $schemaManager->listDatabases(), true)) {
35413550
$connection->executeQuery('CREATE DATABASE foo');
35423551
}
35433552
$connection->executeQuery('USE foo');

0 commit comments

Comments
 (0)