Federico Cargnelutti

Simple is better than complex. Complex is better than complicated. | @fedecarg

Database Helper for PHPUnit

with 2 comments

When testing code which uses the database, you would usually want to make sure the database stays pristine for each test – All tables should be empty, as any extra data could interfere with the tests.

You could probably write an extended Testcase class which automatically does this before each test in setUp and afterwards in tearDown, but it may have some issues. For example, Zend Framework’s Zend_Test Testcase class also extends PHPUnit’s one, and you might need to extend the Zend_Test one as well… and so on.

Luckily, PHPUnit has a way to add event listener that react to certain events.

Continue reading: Database helper for PHPUnit

Written by Federico

August 27, 2008 at 2:43 pm

Posted in Databases, PHP, Programming

2 Responses

Subscribe to comments with RSS.

  1. Looks interesting, I used something far more basic for handling database test. I created a file called setup.php who was called before a test added to the TestSuite and there I do the actual work. This plugin comes just in time :)

    Radoslav Stankov

    August 27, 2008 at 3:08 pm

  2. Yes, Jani’s post is very useful. In my opinion PHPUnit is the way to go.

    Federico

    August 27, 2008 at 4:16 pm


Leave a Reply