Faker Plugin
Overview
The Faker Plugin for Pest provides additional functions for using the Faker library.
Source code: github.com/pestphp/pest-plugin-faker
Installation
Install the Faker Plugin via the Composer package manager:
1composer require pestphp/pest-plugin-faker --dev
Available functions
faker()
The faker()
function will create an instance of the Faker generator with the default locale (en_US).
1use function Pest\Faker\faker; 2 3it('generates a name using faker', function () { 4 $name = faker()->name; 5 6 // Same as: 7 $name = $this->faker()->name; 8 9 assertIsString($name);10});
The faker()
function also allows you to specify the locale that is used when
creating the instance of the Faker generator.
1use function Pest\Faker\faker;2 3it('generates a name using faker with locale', function () {4 $name = faker('fr_FR')->name;5 6 assertIsString($name);7});
Finally, for the full list of available Faker methods, please refer to the Faker documentation.
Next section: Global Assertions →