Skip to content

Elendev/alice

 
 

Repository files navigation

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
  4. Basic Usage
  5. Framework integration 1. Symfony
  6. Complete Reference
  7. Creating Fixtures 1. YAML 1. PHP
  8. Fixture Ranges
  9. Calling Methods
  10. Specifying Constructor Arguments
  11. Using a factory
  12. Optional Data
  13. Handling Unique Constraints
  14. Handling Relations
  15. References
  16. Multiple References
  17. Self reference
  18. Passing references to providers
  19. Keep Your Fixtures Dry
  20. Fixture Inheritance
  21. Including files
  22. Variables
  23. Parameters
  24. Customize Data Generation
  25. Faker Data
  26. Localized Fake Data TODO: port that change to v2
  27. Default Providers 1. Identity 1. Current 1. Cast
  28. Reuse generated data using objects value
  29. Custom Faker Data Providers
  30. Advanced Guide
  31. Performance
  32. Expression Language (DSL) 1. Parameters 1. Functions 1. Identity 1. Arrays 1. Optional 1. References 1. Property Reference
  33. Extending Alice 1. Custom Flag 1. Custom Instantiation 1. Custom Accessor
  34. Third-party libraries
  35. Contribute
  36. Differences between 2.x and 3.x
  37. Architecture 1. FixtureBuilder 1. Generator
  38. Expression Language
  39. Contributing 1. Testing 1. Profiling
  40. Upgrade
  41. License

Other references:

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.

About

Expressive fixtures generator

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%