Relying on fzaninotto/Faker, Alice allows you to create a ton of fixtures/fake data for use while developing or testing your project. It gives you a few essential tools to make it very easy to generate complex data with constraints in a readable and easy to edit way, so that everyone on your team can tweak the fixtures if needed.
Warning: this doc is being updated for alice 3.0. If you want to check the documentation for 2.x, head this way.
- Installation
- Example
- Getting Started
- Basic Usage
- Framework integration 1. Symfony
- Complete Reference
- Creating Fixtures 1. YAML 1. PHP
- Fixture Ranges
- Calling Methods
- Specifying Constructor Arguments
- Using a factory
- Optional Data
- Handling Unique Constraints
- Handling Relations
- References
- Multiple References
- Self reference
- Passing references to providers
- Keep Your Fixtures Dry
- Fixture Inheritance
- Including files
- Variables
- Parameters
- Customize Data Generation
- Faker Data
- Localized Fake Data TODO: port that change to v2
- Default Providers 1. Identity 1. Current 1. Cast
- Reuse generated data using objects value
- Custom Faker Data Providers
- Advanced Guide
- Performance
- Expression Language (DSL) 1. Parameters 1. Functions 1. Identity 1. Arrays 1. Optional 1. References 1. Property Reference
- Extending Alice 1. Custom Flag 1. Custom Instantiation 1. Custom Accessor
- Third-party libraries
- Contribute
- Differences between 2.x and 3.x
- Architecture 1. FixtureBuilder 1. Generator
- Expression Language
- Contributing 1. Testing 1. Profiling
- Upgrade
- License
Other references:
This is installable via Composer as nelmio/alice:
composer require --dev nelmio/alice:^3.0@beta
Here is a complete example of entity declaration:
Nelmio\Entity\User:
user{1..10}:
username: '<username()>'
fullname: '<firstName()> <lastName()>'
birthDate: '<date()>'
email: '<email()>'
favoriteNumber: '50%? <numberBetween(1, 200)>'
Nelmio\Entity\Group:
group1:
name: Admins
owner: '@user1'
members: '<numberBetween(1, 10)>x @user*'
created: '<dateTimeBetween("-200 days", "now")>'
updated: '<dateTimeBetween($created, "now")>'
You can then load them easily with:
$loader = new Nelmio\Alice\Loader\NativeLoader();
$objectSet = $loader->loadFile(__DIR__.'/fixtures.yml');
Or load an array right away:
$loader = new Nelmio\Alice\Loader\NativeLoader();
$objectSet = $loader->loadData([
\Nelmio\Entity\User::class => [
'user{1..10}' => [
'username' => '<username()>',
'fullname' => '<firstName()> <lastName()>',
'birthDate' => '<date()>',
'email' => '<email()>',
'favoriteNumber' => '50%? <numberBetween(1, 200)>',
],
],
\Nelmio\Entity\Group::class => [
'group1' => [
'name' => Admins,
'owner' => '@user1',
'members' => '<numberBetween(1, 10)>x @user*',
'created' => '<dateTimeBetween("-200 days", "now")>',
'updated' => '<dateTimeBetween($created, "now")>',
],
],
]);
For more information, refer to the documentation.
- Symfony:
- Nette
- Zend Framework 2:
- Framework Agnostic
Check the contribution guide.
Check the upgrade guide.
Released under the MIT License.