From d551354691fe44f24210c487b0851a0a8bb8ee94 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 29 Jul 2024 06:06:22 +0200 Subject: [PATCH 1/2] Allow version of doctrine/data-fixtures to allow installation of doctrine/dbal v2 in tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 87fda24..c98274b 100644 --- a/composer.json +++ b/composer.json @@ -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", From f162cacde25103cbd353a5147918d52cea3a82c4 Mon Sep 17 00:00:00 2001 From: W0rma Date: Mon, 29 Jul 2024 06:13:37 +0200 Subject: [PATCH 2/2] 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(