Developed with love by KnpLabs Hire us for your project!
0

alice

by nelmio

Expressive fixtures generator

Alice - Expressive fixtures generator

Package version
Build Status
SensioLabsInsight
Dependency Status
Gitter
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.

Warning: this doc is being updated for alice 3.0. If you want to check the
documentation for 2.x, head this way.

Table of Contents

  1. Installation
  2. Example
  3. Getting Started
    1. Basic Usage
    2. Framework integration
    3. Symfony
  4. Complete Reference
    1. Creating Fixtures
    2. YAML
    3. PHP
    4. Fixture Ranges
    5. Calling Methods
    6. Specifying Constructor Arguments
    7. Using a factory
    8. Optional Data
    9. 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. Localized Fake Data TODO: port that change to v2
    3. Default Providers
    4. Identity
    5. Current
    6. Cast
    7. Reuse generated data using objects value
    8. Custom Faker Data Providers
  8. Advanced Guide
    1. Performance
    2. Expression Language (DSL)
    3. Parameters
    4. Functions
    5. Identity
    6. Arrays
    7. Optional
    8. References
    9. Property Reference
    10. Extending Alice
    11. Custom Flag
    12. Custom Instantiation
    13. Custom Accessor
  9. Third-party libraries
  10. Contribute
    1. Differences between 2.x and 3.x
    2. Architecture
    3. FixtureBuilder
    4. Generator
    5. Expression Language
    6. Contributing
    7. Testing
    8. Profiling
  11. Upgrade
  12. License

Other references:
- Tutorial: Using Alice in Symfony

Installation

This is installable via Composer as
nelmio/alice:

composer require --dev nelmio/alice:^3.0@beta

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:

$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.

Third-party libraries

Contribute

Check the contribution guide.

Upgrade

Check the upgrade guide.

License

Released under the MIT License.

Copyright (c) 2012 Nelmio

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.