Skip to content

Commit

Permalink
Fix support for doctrine/dbal v2 (#32)
Browse files Browse the repository at this point in the history
* Allow version of doctrine/data-fixtures to allow installation of doctrine/dbal v2 in tests
* Fix compatibility with doctrine/dbal v2
  • Loading branch information
W0rma authored Nov 11, 2024
1 parent 2b88012 commit db8866b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require-dev": {
"codeception/stub": "^4.1.3",
"doctrine/annotations": "^2.0.1",
"doctrine/data-fixtures": "^1.7",
"doctrine/data-fixtures": "^1.6",
"doctrine/orm": "^2.14 || ^3.0",
"phpstan/phpstan": "^1.10.58",
"symfony/cache": "^5.4.35 || ^6.4.3 || ^7.0",
Expand Down
8 changes: 7 additions & 1 deletion src/Codeception/Module/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,13 @@ protected function retrieveEntityManager(): void
);
}

$this->em->getConnection()->getNativeConnection();
$connection = $this->em->getConnection();
if (method_exists($connection, 'getNativeConnection')) {
$connection->getNativeConnection();
} else {
// @phpstan-ignore-next-line
$connection->getWrappedConnection();
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/Codeception/Module/Doctrine2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ protected function _setUp()
require_once $dir . "/CircularRelations/C.php";
require_once $dir . '/EntityWithUuid.php';

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

$connection = DriverManager::getConnection(['driver' => $sqliteDriver, 'memory' => true]);

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

0 comments on commit db8866b

Please sign in to comment.