-
Notifications
You must be signed in to change notification settings - Fork 2
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
loadFixtures() doesn't work with Symfony's dependency injection #12
Comments
Hmm... |
Well, declaring the fixture class as a service isn't anything special - it's even explained at https://symfony.com/doc/3.1/bundles/DoctrineFixturesBundle/index.html#accessing-services-from-the-fixtures
I'm using it this way to inject some helpers and some Symfony parameters. So yes, I'm sure they're not excluded - otherwise the dependency injection wouldn't work when I load the fixtures :-) |
Oh, i see... It seems i had misinterpreted your problem. I'm sorry. I've had problems like that before, for example when using Setter Injection in some trait. Try to: Get the services your fixtures need from the container and create the Fixture object passing them as arguments. $service = $this->tester->grabService(Service::class);
$this->fixtures = new Fixture($service);
$this->fixtures->load(); Now why those specific services are not injected automatically is a different problem. |
Here's the workaround I'm using right now: use Doctrine\Common\DataFixtures\Purger\ORMPurger;
$purger = new ORMPurger($this->entityManager);
$purger->purge();
$this->appFixtures->load($this->entityManager); This looks easier to me, cause with your way I'd have to manually keep the order of constructor arguments in sync, right?
Well, this is the issue I'm talking about :-)
OK, but which is the expected object? After all, my plan would be not to use So would you say this is a bug that can be fixed? Or is this the expected behavior (or just the way it is) - then I'd mention it in the docs of |
Switched to more modern syntax: `User::class` and `[]`
Hi guys, is there any update on this? The official doc says it's legit to inject services into fixtures. |
When the fixture class is a Symfony service with normal dependency injection (i.e. constructor arguments), loading them with
$I->loadFixtures(AppFixtures::class)
leads to this error message:The text was updated successfully, but these errors were encountered: