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

[6.x] Fix Faker Unique caching issue #32703

Merged
merged 2 commits into from
May 6, 2020
Merged

Conversation

deleugpn
Copy link
Contributor

@deleugpn deleugpn commented May 6, 2020

Fixes #32700

I tested this change in my own codebase and it worked. The idea is somewhat simple: Assuming Faker is a singleton, the Container factory is executed only once per test. That means within a test, Faker will do it's job of ensuring uniqueness whenever asked.
As soon as the test finishes and the container is flushed, Laravel will start a container from scratch, which will run the container factory once again and it will clear the unique cache from faker by calling $faker->unique(true) (as suggested #32700 (comment)).

The reason for this description is to pay extra attention in $app->singleton(). This is not something easy to catch on a unit test, after all we're testing if unique works across multiple tests. If somebody ever makes Faker a non-singleton, that would cause the factory to be executed on every instantiation of the class and would again break the unique().

@deleugpn deleugpn changed the title Fix Faker Unique caching issue [6.x] Fix Faker Unique caching issue May 6, 2020
@taylorotwell taylorotwell merged commit 5624bfc into laravel:6.x May 6, 2020
@deleugpn deleugpn deleted the patch-1 branch May 6, 2020 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants