From 97d2570a61cce0dea39be9431ad1877826448719 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 29 Jul 2024 06:13:37 +0200 Subject: [PATCH] Fix compatibility with doctrine/dbal v2 --- src/Codeception/Module/Doctrine.php | 8 +++++++- tests/unit/Codeception/Module/Doctrine2Test.php | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Doctrine.php b/src/Codeception/Module/Doctrine.php index eb6f865..35c79df 100644 --- a/src/Codeception/Module/Doctrine.php +++ b/src/Codeception/Module/Doctrine.php @@ -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(); + } } /** diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index 5ef84f5..ad09560 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -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(