Skip to content

Commit

Permalink
Resolve Faker\Generator out of the container if it is bound
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ejunker committed Jan 1, 2020
1 parent cc3167d commit c1a96b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Illuminate/Foundation/Testing/WithFaker.php
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Testing;

use Faker\Factory;
use Faker\Generator;

trait WithFaker
{
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c1a96b3

Please sign in to comment.