Skip to content

Commit

Permalink
Fix compatibility with doctrine/dbal v2
Browse files Browse the repository at this point in the history
  • Loading branch information
W0rma committed Jul 29, 2024
1 parent 1764988 commit 97d2570
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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 97d2570

Please sign in to comment.