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

Unable to use faker locales with WithFaker trait #31614

Closed
jamesfairhurst opened this issue Feb 27, 2020 · 2 comments · Fixed by #31615
Closed

Unable to use faker locales with WithFaker trait #31614

jamesfairhurst opened this issue Feb 27, 2020 · 2 comments · Fixed by #31615
Labels

Comments

@jamesfairhurst
Copy link
Contributor

  • Laravel Version: 6.14.0
  • PHP Version: 7.4.0
  • Database Driver & Version: n/a

Description:

After recent changes to the WithFaker trait on #30992 trying to use a different locale when testing no longer works.

Also related to #30345

Steps To Reproduce:

New up a laravel, attempt to create a locale faker instance:

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, WithFaker;

    protected function setUpFaker()
    {
        $this->faker = $this->makeFaker('en_GB');

        // attempt to output locale number, always from Faker\Provider\en_US\PhoneNumber
        dd($this->faker->phoneNumber);
    }
}
@AegirLeet
Copy link
Contributor

This happens because

return $this->app->make(Generator::class, [$locale]);
passes the locale as a parameter to make() when getting the Generator from the container, but DatabaseServiceProvider, which binds the Generator at
$this->app->singleton(FakerGenerator::class, function ($app) {
return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));
});
, doesn't use that value at all .

@jamesfairhurst
Copy link
Contributor Author

@AegirLeet yeah, personally I would be leaning to revert #30992 as the use case was quite specific and could be handled in an overridden setUpFaker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants