Description
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.
Alice alternatives and similar libraries
Based on the "Testing" category.
Alternatively, view Alice alternatives based on common mentions on social networks and blogs.
-
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). -
VFS Stream
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest. -
PHP-Mock: mocking built-in PHP functions
Mock built-in PHP functions (e.g. time(), exec() or rand())
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Alice or a related project?
Popular Comparisons
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](doc/getting-started.md)
- [Basic Usage](doc/getting-started.md#basic-usage)
- [Framework integration](doc/getting-started.md#framework-integration)
- [Symfony](doc/getting-started.md#symfony)
- [Complete Reference](doc/complete-reference.md)
- [Creating Fixtures](doc/complete-reference.md#creating-fixtures)
- [YAML](doc/complete-reference.md#yaml)
- [PHP](doc/complete-reference.md#php)
- [JSON](doc/complete-reference.md#json)
- [Fixture Ranges](doc/complete-reference.md#fixture-ranges)
- [Fixture Lists](doc/complete-reference.md#fixture-lists)
- [Fixture Reference](doc/complete-reference.md#fixture-reference)
- [Calling Methods](doc/complete-reference.md#calling-methods)
- [Method arguments with flags](doc/complete-reference.md#method-arguments-with-flags)
- [Method arguments with parameters](doc/complete-reference.md#method-arguments-with-parameters)
- [Specifying Constructor Arguments](doc/complete-reference.md#specifying-constructor-arguments)
- [Using a factory / a named constructor](doc/complete-reference.md#using-a-factory--a-named-constructor)
- [Optional Data](doc/complete-reference.md#optional-data)
- [Handling Unique Constraints](doc/complete-reference.md#handling-unique-constraints)
- [Creating Fixtures](doc/complete-reference.md#creating-fixtures)
- [Handling Relations](doc/relations-handling.md)
- [References](doc/relations-handling.md#references)
- [Multiple References](doc/relations-handling.md#multiple-references)
- [Self reference](doc/relations-handling.md#self-reference)
- [Passing references to providers](doc/relations-handling.md#passing-references-to-providers)
- [Keep Your Fixtures Dry](doc/fixtures-refactoring.md)
- [Fixture Inheritance](doc/fixtures-refactoring.md#fixture-inheritance)
- [Including files](doc/fixtures-refactoring.md#including-files)
- [Variables](doc/fixtures-refactoring.md#variables)
- [Parameters](doc/fixtures-refactoring.md#parameters)
- [Static parameters](doc/fixtures-refactoring.md#static-parameters)
- [Dynamic parameters](doc/fixtures-refactoring.md#dynamic-parameters)
- [Composite parameters](doc/fixtures-refactoring.md#composite-parameters)
- [Usage with functions (constructor included)](doc/fixtures-refactoring.md#usage-with-functions-constructor-included)
- [Inject external parameters](doc/fixtures-refactoring.md#inject-external-parameters)
- [Customize Data Generation](doc/customizing-data-generation.md)
- [Faker Data](doc/customizing-data-generation.md#faker-data)
- [Localized Fake Data](doc/customizing-data-generation.md#localized-fake-data)
- [Random data](doc/customizing-data-generation.md#random-data)
- [Default Providers](doc/customizing-data-generation.md#default-providers)
- [Identity](doc/customizing-data-generation.md#identity)
- [Current](doc/customizing-data-generation.md#current)
- [Cast](doc/customizing-data-generation.md#cast)
- [Custom Faker Data Providers](doc/customizing-data-generation.md#custom-faker-data-providers)
- [Faker Data](doc/customizing-data-generation.md#faker-data)
- [Advanced Guide](doc/advanced-guide.md#advanced-guide)
- [Performance](doc/advanced-guide.md#performance)
- [Expression Language (DSL)](doc/advanced-guide.md#expression-language-dsl)
- [Parameters](doc/advanced-guide.md#parameters)
- [Functions](doc/advanced-guide.md#functions)
- [Identity](doc/advanced-guide.md#identity)
- [Arrays](doc/advanced-guide.md#arrays)
- [Optional](doc/advanced-guide.md#optional)
- [References](doc/advanced-guide.md#references)
- [Property Reference](doc/advanced-guide.md#property-reference)
- [Extending Alice](doc/advanced-guide.md#extending-alice)
- [Custom Flag](doc/advanced-guide.md#custom-flag)
- [Custom Instantiation](doc/advanced-guide.md#custom-instantiator)
- [Custom Accessor](doc/advanced-guide.md#custom-accessor)
- Third-party libraries
- [Contribute](CONTRIBUTING.md#contribute)
- [Differences between 2.x and 3.x](CONTRIBUTING.md#differences-between-2x-and-3x)
- [Architecture](CONTRIBUTING.md#architecture)
- [FixtureBuilder](CONTRIBUTING.md#fixturebuilder)
- [Generator](CONTRIBUTING.md#generator)
- [Expression Language](CONTRIBUTING.md#expression-language)
- [Contributing](CONTRIBUTING.md#contributing)
- [Testing](CONTRIBUTING.md#testing)
- [Profiling](CONTRIBUTING.md#profiling)
- Backward Compatibility Promise (BCP)
- Upgrade
- [Breaking changes between Alice 2.x and 3.0](UPGRADE.md#breaking-changes-between-alice-2x-and-30)
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](CONTRIBUTING.md).
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](UPGRADE.md).
*Note that all licence references and agreements mentioned in the Alice README section above
are relevant to that project's source code only.