Does anyone have a link to a good, working tutorial or book on how to get started with adding the DBUnit layer to my PHPUNit tests?
I've tried following the code in
protected function getDatabaseTester()
{
$pdo = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
$connection = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($pdo);
$tester = new PHPUnit_Extensions_Database_DefaultTester($connection);
$tester->setSetUpOperation(PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT());
$tester->setTearDownOperation(PHPUnit_Extensions_Database_Operation_Factory::NONE());
/*
* the next line fails with the error
PHP Fatal error: __autoload(): Failed opening required 'PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet.php' (include_path= ***
*/
$tester->setDataSet(new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__).'/../../../files/xml_database_export.xml'));
return $tester;
}
The XML is created via mysqldump command. I'd happily use CSV, or even an array in memory (whatever works)
Unfortunately I just can't seem to get this system started.
There is a chapter to Database testing in the PHPUnit manual:
And B. Eberlei's Ultimate Guide to DB Testing with PHPUnit
There is also a Blogpost by PHPUnit's author Sebastian Bergmann on the topic (2008 though):
Some even older blog posts by Mike Lively, the author the DbUnit extension can be found at
A more recent tutorial (2010) would be in Matthew Turland's Blog:
You can also visit #phpunit on Freenode IRC to get official support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With