Zend_PHPUnit_Fixtures uploaded to GitHub

December 4, 2008

Well I’ve been working on this project (Zend PHPUnit Fixtures) along with a few collegues over the past few months, It was my intension to submit it to Zend some point in the new year but thought I’d put it out in the wild for others to pick at.

Well I use TDD (PHPUnit is my friend) on a daily basis within ZendFramework and soon found it cumbersome to create test data (fixtures) ending up in huge test cases with more test data setup than actual assertions, this matched up with the fact that I hate integrating DB into my tests (mainly because the tables would still contain old test data & fail depending on whether the data was added in previous tests or not) So I decided to do some digging, the best solution seemed to be to create a fixture handling system that plugs into ZendFramework, leaving myself and others with more time actually testing and less time building up test data and removing fixtures from a database (which can be near impossible when it comes to automated testing).

With this realisation I decided to create my own which I’ve reversed engineered from CakePHP. When I have the time (hopefully over the holidays) I’ll go into how the mini framework can be used. For now I’ll just describe the features or each class and what they are for:-


Basic fixture handler, used for creating test data that does not interact with a DB. With this object we are able to create basic fixtures that we can use for dummy data with our test cases. Each piece of test data can have an alias (‘ALIAS’) with the aliases name as the value, doing so will allow us to use the PHPUnit_Fixtures::find($aliasName) which will retrieve the desired fixture.


Has the same functionality as PHPUnit_Fixtures but used specifically for DB centric tests, DB test data will be added to our ‘_test’ DB, and cleaned up (truncated) on each test case, to make sure that we have the expected data.


Has the same functionality as PHPUnit_Fixture_DB, with the added functionality of being able to create tables setup my MySQL Workbench. With an child object of this class we are able to specify retrieving all schema or a specific on (denoted by the schema table name).


Used to handle our development environments, there are times when we want to quickly place test data on our staging DB for functionality testing and the such like, this class along with one of our PHPUnit_Fixtures, will easily allow us to populate this environment with the data we have been using for our unit tests, making it quicker to migrate test data from one place to another.

You can find the project at GitHub, If anyones interested in adding to this project or have any comments/questions drop me a line.



  1. This is very interesting stuff indeed! This seems to take a different tack from the DBUnit support in PHPUnit currently, and feels much more flexible.

    Have you pinged Sebastian about contributing it to PHPUnit?

  2. That’s definately on the books, last few days I’ve just been cleaning up the tests and going through the documentation, hopefully over the holidays I’ll have time to officially put to him.

  3. Sounds interesting. Will look into it when I find the time.

  4. If you want to put our heads together and determine how some of this can be folded into the dbunit support (or how dbunit support can be made more flexible. Track me down. @mlively on twitter.

  5. Hiya Mike, cheers for the response, that sounds like a great idea. After speaking with Sebastien, the first thing I want to do is get my head around DbUnit some more (specifically using arrays as fixtures) then I can get a better understanding of how both projects are overlapping.

    The main premise for this project was to provide a fixtures system for ZendFramework that is as flexible as possible, as my colleagues need to be able to create and use them with little knowledge of the underlying structure, if PHPUnit/DbUnit could deal with (mainly auto generating fixtures, fixture aliasing & setup/teardown of test data/DB’s, see PHPUnit_Fixtures_DB/PHPUnit_Fixtures_DynamicDB) this solely that would be heavenly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: