Generating fixtures with Alice

A common problem in software development, is that you need data to work with. This is especially true with data-oriented websites. Working with an empty database leads to all sorts of unexpected problems cropping up once the site goes live and receives real world data. Performance issues, visual bugs due to missing fields, too long or too small texts, etc.

The best way to address this is to have fixtures, fake data you use while developing or for automated testing of the website. However writing these fixtures can be a cumbersome process which leads to people postponing it and sometimes outright skip this step.

It used to be that Doctrine1 could load fixtures from yaml files, and symfony1 also had facilities there, but none of this has been made available to Doctrine2 or Symfony2 yet, or at least not in a very usable form.

Instead of writing a plugin for either of those, I set out to write a generic library to easily create objects from yaml files. It can be used with any framework or ORM, and also integrates the great Faker library to generate fake/random data. The library takes a few opinionated turns, so it might not be for everyone. However I am sure it will save you a great deal of time should you decide to work with it.

The library is called Alice, after the common Alice and Bob placeholder names, and you can of course find it on GitHub, including extensive documentation.

Let me know what you think of it!

October 29, 2012 by Jordi Boggiano in Development, News // Tags: , , 18 Comments

18 Responses to Generating fixtures with Alice

  1. cordoval says:

    great that it works well with faker

  2. Victor P says:

    What is wrong with the current doctrine 2 fixtures bundle?

    • It’s fine, but you have to write everything by hand, which in my experience leads to a ton of duplication and boilerplate if you want somewhat interesting fixtures. Alice tries to help with that problem, but if you don’t feel it’s a problem that’s alright too.

  3. Gilles Doge says:

    Really cool !

    I use doctrine fixtures a lot (completed sometimes with Faker) but it’s hard to maintain a take a lot of time.

    I like this new approach.

  4. Does it work together with Doctrine MongoDB Bundle?

  5. maczek says:

    I’ve never used fixtures and functional tests at all… I created the YAML file, loaded it in my WebTestCase but don’t know what next. I created action test with:

    $crawler = $this->client->request('GET', '/session/1');

    And want my controller to get the session (id=1) defined in the YAML file instead of one from the database. How to do this?

  6. b0ro says:

    Are there any examples with xml files?

    • It does not have an XML loader yet so no. Only yaml and plain php arrays are supported, but you could use something to convert xml to an array and then load the array.

  7. Ayoub says:

    Hello there, Any chance that this bundle is supporting Doctrine ODM?

  8. Very nice and helpfull Bundle ! Thank you for moving us back to the good times when Symfony was great as a GIANT. Now lack lot of oldies and goldies ;)

  9. Thanks for this library!

  10. Chris Jones says:

    Hi. I find this useful, but I’m wondering if there is anyway to pass some options? eg –file=test.yml –buildacl

  11. Rebolon says:

    I read really quickly the doc, but one question : is it easy to bind with nelmio api doc ? the aim would be to get the post/pu form filled with fake data. Thanks