From c1a96b3f2f0d2bde90a9eafb1071c7dfca59a3d1 Mon Sep 17 00:00:00 2001 From: Eric Junker Date: Tue, 31 Dec 2019 20:38:55 -0600 Subject: [PATCH] Resolve Faker\Generator out of the container if it is bound 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 --- src/Illuminate/Foundation/Testing/WithFaker.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Testing/WithFaker.php b/src/Illuminate/Foundation/Testing/WithFaker.php index eb1b67b0137e..fbcfc7687e30 100644 --- a/src/Illuminate/Foundation/Testing/WithFaker.php +++ b/src/Illuminate/Foundation/Testing/WithFaker.php @@ -3,6 +3,7 @@ namespace Illuminate\Foundation\Testing; use Faker\Factory; +use Faker\Generator; trait WithFaker { @@ -42,6 +43,12 @@ protected function faker($locale = null) */ protected function makeFaker($locale = null) { - return Factory::create($locale ?? config('app.faker_locale', Factory::DEFAULT_LOCALE)); + $locale = $locale ?? config('app.faker_locale', Factory::DEFAULT_LOCALE); + + if ($this->app->bound(Generator::class)) { + return $this->app->make(Generator::class, [$locale]); + } + + return Factory::create($locale); } }