News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

CodeUtopia Blog:
Database helper for PHPUnit
August 28, 2008 @ 10:22:12

On the CodeUtopia blog there's a recent post with info on creating a custom event listener in PHPUnit that can help keep you database data completely clean.

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. [...] Luckily, PHPUnit has a way to add event listener that react to certain events.

It uses the TestListener interface to make the event handler that (with the help of Doctrine) starts up, makes the tables with data and wipes them out at the end.

Code for the sample listener is in the post and included is the method for checking to see if you even need to use the database or not.

0 comments voice your opinion now!
database phpunit event listener database testlistener


blog comments powered by Disqus

Similar Posts

Matt Butche's Blog: MongoDB: 5 Things Every PHP Developer Should Know About MongoDB

Sebastian Bergmann's Blog: Sharing Fixtures and Stubbing/Mocking Static Methods

Sameer Borate's Blog: Selenium IDE Tutorial - Part 2

Fabian Schmengler's Blog: "Mocking" built-in functions like time() in Unit

Sameer Borate: Efficiently Replicating RETS data to MySQL


Community Events

Don't see your event here?
Let us know!


api community symfony2 version opinion extension podcast conference release example framework laravel php7 performance library series interview introduction voicesoftheelephpant xdebug

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework