-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Testings Types from the Service Container doesn't find dependencies #36462
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
Comments
Well, you will need to register the DoctrineExtension in your TypeTestCase if you rely on the Doctrine types in the form you test. |
Thank you, how would you do this ? And should it be added to the documentation ? |
See the next chapter in the docs you linked: https://symfony.com/doc/current/form/unit_testing.html#adding-custom-extensions |
IMHO, this is not clear enough. First, without documentation, I don't think everybody will know that the DoctrineOrmExtension is required for a form with a EntityType. Then, the extension is not easy to use. You have to write
But you need a $registry ! If we go deep in some tests written by Symfony, we can find a way to get a $registry:
This can also be found in StackOverflow But this only works with
This error can be found on StackOverflow without any resolution. Maybe I missed an easy solution but in my case, I only made it work with:
Which is far from being easy. |
Hello @VincentLanglet, I agree we need a doc update, I have opened symfony/symfony-docs#13552. The I think we should close here though as there is nothing we can do about it in core. |
Indeed, the kernel would be useful. |
Both should not be related. The |
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [Form] Updated unit testing article Ref symfony/symfony#36462. Commits ------- de0d1fb [Form] Updated unit testing article
Closing as that's related to the doc and this staled here. |
Symfony version(s) affected: 4.4.7
Description
In my case I can't test a type with a dependency, I get the following error :
How to reproduce
Possible Solution
Additional context
The construct of my type :
The link of the documentation :
https://symfony.com/doc/current/form/unit_testing.html#testings-types-from-the-service-container
The text was updated successfully, but these errors were encountered: