nelmio/alice
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
fakerphp/faker | v1.23.1 | 3.36 MB | MIT | prod | |
myclabs/deep-copy | 1.11.1 | 22.96 kB | MIT | prod | |
sebastian/comparator | 6.0.0 | 19.57 kB | BSD-3-Clause | prod | |
symfony/property-access | v7.0.7 | - | MIT | prod | |
symfony/yaml | v7.0.7 | - | MIT | prod |
Nelmio/Alice is a comprehensive library built to manage the generation of fake data, also known as fixtures, for PHP projects. It leverages the capabilities of the FakerPHP/Faker library, providing an expressive and easy-to-use interface to create large volumes of complex data for use in project development and testing. The library is capable of generating data that satisfies a range of constraints and is organized in a way that allows everyone on your team to easily tweak the generated fixtures as needed.
To use Nelmio/Alice, you first need to install it via Composer as nelmio/alice by running the following command in your terminal:
composer require --dev nelmio/alice
To begin generating fixtures with Nelmio/Alice, simply create a file specifying the entity definitions and desired data constraints. This can be expressed in YAML syntax, as shown:
Nelmio\Entity\User:
user{1..10}:
username: '<username()>'
fullname: '<firstName()> <lastName()>'
birthDate: '<date_create()>'
email: '<email()>'
favoriteNumber: '50%? <numberBetween(1, 200)>'
Once you've specified your fixture data, you can load it using PHP, as the following example describes:
$loader = new Nelmio\Alice\Loader\NativeLoader();
$objectSet = $loader->loadFile(__DIR__.'/fixtures.yml');
You can also load fixtures directly from an array:
$loader = new Nelmio\Alice\Loader\NativeLoader();
$objectSet = $loader->loadData([
\Nelmio\Entity\User::class => [
'user{1..10}' => [
'username' => '<username()>',
'fullname' => '<firstName()> <lastName()>',
'birthDate' => '<date_create()>',
'email' => '<email()>',
'favoriteNumber' => '50%? <numberBetween(1, 200)>',
],
],
]);
The Nelmio/Alice documentation is available and up-to-date on GitHub, and it contains an exhaustive reference for using the library. You can find in-depth explanations, added examples, and covering other related topics that can provide a more profound understanding. For the more advanced topics, see "Advanced Guide" and "Customize Data Generation". For contributing to the project, check the "Contribute" section. Documentation for previous versions is also accessible if required. Find the complete documentation on GitHub at the following link.