views:

98

answers:

1

I have a MySQL file that represents my database in a specific state that would allow me to test a class I am working on. What I want to do is have PHPUnit clean and rebuild the database from this file for each test or set of tests.

How can I go about that without having to resort to rewriting the data in the XML format that PHPUnit uses?

+1  A: 

I usually maintain a bootstrap.php file that handles dependency injection and calling a db.sql file. I call that each time one of my PHPUnit suites are called.

For row-specific changes, I tend to put those in my __construct() method for the unit test or in my individual test case methods. That way it's easier to track them if I need to change them.

Hope that helps a little.

Inkspeak
@Inkspeak Do you have any example code that would be helpful?
Ben Dauphinee
@Ben Dauphinee, I'll see if I can dig up an example when I head back to work. The bootstrap file is what you generally get with your Zend Framework MVC deployment. You change the APPLICATION_ENV to register as 'unittest' which will allow you to move your configurations to the application.ini file. After that it's your suite setup and unit tests (which I'll try and dig up for you).
Inkspeak