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

[5.6] Add faker helper #23451

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ function factory()
}
}

if (! function_exists('faker')) {
/**
* Create a Faker instance for the given locale.
*
* @param string $locale
* @return \Faker\Generator
*/
function faker($locale = null)
{
return \Faker\Factory::create($locale ?? \Faker\Factory::DEFAULT_LOCALE);
}
}

if (! function_exists('info')) {
/**
* Write some information to the log.
Expand Down
6 changes: 6 additions & 0 deletions tests/Foundation/FoundationHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ public function testMixDoesNotIncludeHost()

unlink(public_path('mix-manifest.json'));
}

public function testFakerIsCreated()
{
$this->assertTrue(faker() instanceof \Faker\Generator);
$this->assertTrue(faker('fr_FR') instanceof \Faker\Generator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use $this->assertInstanceOf('\Faker\Generator', faker()); here for clearer errors 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, I’m camping for the weekend, but if there is interest in this and it hasn’t been canned by the boss, I’ll tweak this on Monday (Aus Time).
Thanks for the tip!

}
}