Loading Yaml Fixtures in Symfony2 and Doctrine2

I recently found on Coil’s blog, here: http://www.strangebuzz.com/post/2012/01/28/Load-fixtures-with-Symfony2 how he went about creating fixtures from Yaml files in Symfony2. This is something that I’ve been willing to have for a while.

But I needed more than just loading the data from Yaml. My need for easy to use fixtures comes from testing and setting up the database for test purposes. Fixtures can have many different needs. You might need some of them in production because they bootstrap your database (for example set the client_contract possible status to prospect, proposal, signed_contract in a contract_status table), some of them are required for development. And some of them for testing of course and for testing you might even want different possible cases.

New Bundle!

Based on this idea I created a new bundle for this purpose: https://github.com/khepin/KhepinYamlFixturesBundle

The bundle allows you to define fixture files in the YAML format of course. You have a command line tool to load all your fixtures in database. As well as a service living in the DIC so that you can load fixtures in your test setup function.

Contexts

The bundle provides a notion of “contexts” which might be the ‘production’, ‘test’, ‘dev’ cases we just talked about for example. This allows you to either load only the standards fixtures or load the standard ones plus the ones specific of a given context.

Well that’s it for now, but I hope it helps many of you I’ve seen looking for this on the interwebs. Any feedback is welcome to help make it more usable for not just me.

4 thoughts on “Loading Yaml Fixtures in Symfony2 and Doctrine2

  1. How do I setup khepin with deps.
    I got this error in app/console:

    PHP Fatal error: Class ‘Khepin\YamlFixturesBundle\KhepinYamlFixturesBundle’ not found in /home/epsi/www/symfony2/book2/app/AppKernel.php on line 31

    • Hey did you add the Khepin namespace in your autoload file?
      Also the master branch is not compatible with symfony 2.0. For that you need the “2.0″ branch.

Comments are closed.