开发者

How can I use PHPUnit to set up and tear down the database using a SQL file?

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 rew开发者_如何学运维riting the data in the XML format that PHPUnit uses?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜