foundry: Question/Problem: Using Foundry in Doctrine Fixtures with service injection
I want to use UserPasswordEncoderInterface
in my UserFactory
to set the encoded password after instantiate. When I try to create my Factory ($userAdmin = UserFactory::new();
), I get:
Model Factories with dependencies (Model Factory services) cannot be used without the foundry bundle.
but Flex registered the Bundle: Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
It looks like Foundry has booted, but the injected $factories
in \Zenstruck\Foundry\ModelFactoryManager
are empty.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (11 by maintainers)
ok, thanks, good to know… this is… very strange! 😅
@nikophil
hey @nikophil good finding, I commented the
exclude
lines and now UserFactory is up, with proper tag so, I need to review my excludes… Thank you very much!What does your
config/services.yaml
look like? Any exclusions forsrc/User
?I tried a branch new
symfony new --version=lts
withcomposer require --dev zenstruck/foundry
and couldn’t re-create your issue. I think it’s your config.https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#stories-as-services describes that the tag is needed (below the example). Could probably make that pop a bit more with it as a note.
I’ve encountered this issue:
bin/console doctrine:fixtures:load --append -n
=>Stories with dependencies (Story services) cannot be used without the foundry bundle.
Fix: set autoconfigure and autowire true to said service:
Hello, I think perhaps your factories are not being autowired/autoconfigured. Can you find the service with
bin/console debug:container
?