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:

composer 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).

use function Pest\Faker\faker;

it('generates a name using faker', function () {
    $name = faker()->name;

    // Same as:
    $name = $this->faker()->name;

    assertIsString($name);
});

The faker() function also allows you to specify the locale that is used when creating the instance of the Faker generator.

use function Pest\Faker\faker;

it('generates a name using faker with locale', function () {
    $name = faker('fr_FR')->name;

    assertIsString($name);
});

Finally, for the full list of available Faker methods, please refer to the Faker documentation.


Next section: Global Assertions →