-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[6.x] Resolve Faker\Generator out of the container if it is bound #30992
Conversation
If Faker\Generator is bound in the container then use that instance instead of creating a default version. This allows you to bind your own custom Faker\Generator and add custom faker providers which will be available when using WithFaker
I don't quite follow why you'd need this. Why not just make your own trait? |
Not sure what's going on here, but this seems to have broken several dozen unit tests in one of my projects. Some of my tests use data providers and some of those use faker to generate some test data. This now fails. I've just started to look at it, but I wanted to raise the flag in case someone can save me time or is also experiencing the same problem. It may be that I need to make changes in my code...or it may be that this PR has caused an issue. |
Thx @driesvints . I just came back here to link the fix...looks like you've already done so...and I can now see that it was already linked. Could have saved myself a bit of time...! ;-) I think I'll take a break now.... :-) |
I think this prevents locale changes from working too as it always resolves the Overriding the trait in a test and attempting to create a specific locale instance doesn't seem to be working for me e.g.
This is in a package and has been working for me in the past so I think a Edit:
As the generater doesn't have a constructor attempting to I would personally revert this commit, although it solves a specific case it's probably best to keep this as generic as possible and if a custom provider is required (like the example driving the change) simply override the |
If Faker\Generator is bound in the container then use that instance instead of creating a default version. This allows you to bind your own custom Faker\Generator and add custom faker providers which will be available when using WithFaker
For example, you can create a FakerServiceProvider that can bind it like this:
The code is adding the custom CompanyNameGenerator faker provider. Since it is bound in the container then it will be used and the custom company name provider will be available to be used. Without this change then the CompanyNameGenerator provider would not be available and would have to be manually added everytime you wanted to use it.