Skip to content

nelmio/alice

 
 

Repository files navigation

Alice - Expressive fixtures generator

Package version Build Status Slack License

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.

You are reading the documentation for the 2.x branch. If you want to head back to the latest version, click here.

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

  1. Installation
  2. Example
  3. Getting Started
    1. Basic Usage
    2. Detailed Usage
  4. Complete Reference
    1. Creating Fixtures
    2. Fixture Ranges
    3. Fixture Lists
    4. Calling Methods
    5. Specifying Constructor Arguments
    6. Custom Setter
    7. Optional Data
    8. Handling Unique Constraints
  5. Handling Relations
    1. References
    2. Multiple References
    3. Self reference
    4. Passing references to providers
  6. Keep Your Fixtures Dry
    1. Fixture Inheritance
    2. Including files
    3. Variables
    4. Parameters
  7. Customize Data Generation
    1. Faker Data
    2. Reuse generated data using objects value
    3. Custom Faker Data Providers
  8. Event handling with Processors
  9. Third-party libraries
    1. Symfony
    2. Nette
    3. Zend Framework 2

Other references:

Installation

This is installable via Composer as nelmio/alice:

composer require --dev nelmio/alice:^2.0

Example

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:

$objects = \Nelmio\Alice\Fixtures::load(__DIR__.'/fixtures.yml', $objectManager);

For more information, refer to the documentation.

Third-party libraries

Symfony

Nette

Zend Framework 2: