Skip to content

Commit db8866b

Browse files
authored
Fix support for doctrine/dbal v2 (#32)
* Allow version of doctrine/data-fixtures to allow installation of doctrine/dbal v2 in tests * Fix compatibility with doctrine/dbal v2
1 parent 2b88012 commit db8866b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require-dev": {
2626
"codeception/stub": "^4.1.3",
2727
"doctrine/annotations": "^2.0.1",
28-
"doctrine/data-fixtures": "^1.7",
28+
"doctrine/data-fixtures": "^1.6",
2929
"doctrine/orm": "^2.14 || ^3.0",
3030
"phpstan/phpstan": "^1.10.58",
3131
"symfony/cache": "^5.4.35 || ^6.4.3 || ^7.0",

src/Codeception/Module/Doctrine.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,13 @@ protected function retrieveEntityManager(): void
262262
);
263263
}
264264

265-
$this->em->getConnection()->getNativeConnection();
265+
$connection = $this->em->getConnection();
266+
if (method_exists($connection, 'getNativeConnection')) {
267+
$connection->getNativeConnection();
268+
} else {
269+
// @phpstan-ignore-next-line
270+
$connection->getWrappedConnection();
271+
}
266272
}
267273

268274
/**

tests/unit/Codeception/Module/Doctrine2Test.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ protected function _setUp()
7171
require_once $dir . "/CircularRelations/C.php";
7272
require_once $dir . '/EntityWithUuid.php';
7373

74-
$connection = DriverManager::getConnection(['driver' => 'sqlite3', 'memory' => true]);
74+
$sqliteDriver = 'sqlite3';
75+
// The driver "sqlite3" is only available as-of doctrine/dbal:3.5
76+
// Use "pdo_sqlite" for older versions
77+
if (version_compare(InstalledVersions::getVersion('doctrine/dbal'), '3.5', '<')) {
78+
$sqliteDriver = 'pdo_sqlite';
79+
}
80+
81+
$connection = DriverManager::getConnection(['driver' => $sqliteDriver, 'memory' => true]);
7582

7683
if (version_compare(InstalledVersions::getVersion('doctrine/orm'), '3', '>=')) {
7784
$this->em = new EntityManager(

0 commit comments

Comments
 (0)