nelmio / alice
Expressive fixtures generator
Fund package maintenance!
theofidry
Installs: 35 761 573
Dependents: 155
Suggesters: 4
Security: 0
Stars: 2 505
Watchers: 48
Forks: 328
Open Issues: 46
Requires
- php: ^8.1
- fakerphp/faker: ^1.10
- myclabs/deep-copy: ^1.10
- sebastian/comparator: ^3.0 || ^4.0 || ^5.0 || ^6.0
- symfony/property-access: ^6.4 || ^7.0
- symfony/yaml: ^6.0 || ^7.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.1
- phpspec/prophecy: ^1.6
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.3
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/finder: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
- symfony/phpunit-bridge: ^6.4 || ^7.0
- symfony/var-dumper: ^6.4 || ^7.0
Suggests
- theofidry/alice-data-fixtures: Wrapper for Alice to provide a persistence layer.
Conflicts
- symfony/framework-bundle: <6.4.0
- dev-main
- 3.13.6
- 3.13.5
- 3.13.4
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13.0
- 3.12.2
- 3.12.1
- 3.12.0
- v3.11.0
- v3.10.0
- v3.9.0
- v3.8.2
- v3.8.1
- v3.8.0
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- v3.7.0
- v3.6.0
- v3.5.8
- v3.5.7
- v3.5.6
- v3.5.5
- v3.5.4
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.0
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0.0
- v3.0.0-RC.1
- v3.0.0-RC.0
- v3.0.0-beta.5
- v3.0.0-beta.4
- v3.0.0-beta.3
- v3.0.0-beta.2
- v3.0.0-beta.1
- v3.0.0-beta.0
- 2.x-dev
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.1
- v2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.x-dev
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- dev-dependabot/composer/vendor-bin/phpstan/dependencies-07dd3a82b6
This package is auto-updated.
Last update: 2024-12-06 13:39:28 UTC
README
Alice - Expressive fixtures generator
Relying on FakerPHP/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 for alice 3.0. If you want to check the documentation for 2.x, follow this link.
2.x is in maintenance mode: PRs are accepted, but no active development is done on it by the maintainers any longer.
Table of Contents
- Installation
- Example
- Getting Started
- Complete Reference
- Handling Relations
- Keep Your Fixtures Dry
- Customize Data Generation
- Advanced Guide
- Third-party libraries
- Contribute
- Backward Compatibility Promise (BCP)
- Upgrade
Installation
This is installable via Composer as nelmio/alice:
composer require --dev nelmio/alice
Example
Here is a complete example of entity declaration:
Nelmio\Entity\User: user{1..10}: username: '<username()>' fullname: '<firstName()> <lastName()>' birthDate: '<date_create()>' 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_create()>', '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.
Third-party libraries
Framework Agnostic
Symfony
Nette
WordPress
Zend Framework 2:
Contribute
Check the contribution guide.
Backward Compatibility Promise (BCP)
The policy is for the major part following the same as Symfony's one with a few changes or highlights:
- Code marked with
@private
or@internal
are excluded from the BCP Nelmio\Alice\Loader\NativeLoader
is excluded from the BCP: as it is the no DIC solution, registring a new service may require a new method, in which case your code may break if you have already declared that method. To avoid that, please beware of the naming of your methods to avoid any conflicts.
Upgrade
Check the upgrade guide.