Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Doctrine.php: Adding dependency injection workaround to load fixtures #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Codeception/Module/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <?php
Expand All @@ -679,8 +678,7 @@ private function extractPrimaryKey(object $instance)
* $I->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
* <?php
Expand All @@ -689,6 +687,20 @@ 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 (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
* <?php
* $someService = $I->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<FixtureInterface>|class-string<FixtureInterface>[]|list<FixtureInterface> $fixtures
* @param bool $append
* @throws ModuleException
Expand Down
Loading