From 0fff74a78e2574df3cfab03fff1937a806bb9514 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 1 Dec 2024 00:06:37 +0100 Subject: [PATCH 1/2] Update Doctrine.php: Adding dependency injection workaround to load fixtures --- src/Codeception/Module/Doctrine.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Codeception/Module/Doctrine.php b/src/Codeception/Module/Doctrine.php index 35c79df..1f0c404 100644 --- a/src/Codeception/Module/Doctrine.php +++ b/src/Codeception/Module/Doctrine.php @@ -669,8 +669,7 @@ private function extractPrimaryKey(object $instance) } /** - * Loads fixtures. Fixture can be specified as a fully qualified class name, - * an instance, or an array of class names/instances. + * Loads fixtures. The fixture class can be specified as a fully qualified class name, an instance, or an array of class names/instances. * * ```php * loadFixtures(new AppFixtures); * ``` * - * By default fixtures are loaded in 'append' mode. To replace all - * data in database, use `false` as second parameter: + * By default, the fixtures are loaded in 'append' mode. To replace all data in database, pass `false` as second parameter: * * ```php * runShellCommand('php bin/console doctrine:fixtures:load --no-interaction --env=test'); + * ``` + * * @param class-string|class-string[]|list $fixtures * @param bool $append * @throws ModuleException From 6e22f5048d455072c095c80837eed485c905d2d0 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 9 Jan 2025 15:34:46 +0100 Subject: [PATCH 2/2] Update Doctrine.php --- src/Codeception/Module/Doctrine.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Codeception/Module/Doctrine.php b/src/Codeception/Module/Doctrine.php index 1f0c404..0413ca3 100644 --- a/src/Codeception/Module/Doctrine.php +++ b/src/Codeception/Module/Doctrine.php @@ -687,12 +687,19 @@ private function extractPrimaryKey(object $instance) * * This method requires [`doctrine/data-fixtures`](https://github.com/doctrine/data-fixtures) to be installed. * - * If your fixture class uses Symfony's Dependency Injection, this method will not work. In this case, you can load your fixtures like this - * (requires [Module Cli](https://codeception.com/docs/modules/Cli)): - * - * ```bash - * $I->runShellCommand('php bin/console doctrine:fixtures:load --no-interaction --env=test'); - * ``` + * If your fixture class uses Symfony's Dependency Injection (i.e. has constructor arguments), this method will not work. In this case, you have 3 options: + * * Recommended: Try to get rid of those dependencies, possibly by moving their work into the very test. + * * Manually pass the constructor arguments like this: + * ```php + * grabService(SomeService::class); + * $appFixtures = new AppFixtures($someService); + * $appFixtures->load(); + * ``` + * * Load your fixtures like this (requires [Module Cli](https://codeception.com/docs/modules/Cli)): + * ```bash + * $I->runShellCommand('php bin/console doctrine:fixtures:load --no-interaction --env=test'); + * ``` * * @param class-string|class-string[]|list $fixtures * @param bool $append