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.
TRUNCATE
s (erases) a table and populates it with custom data you provide from an XML. Apparently, that's it. No magical persistent connection, no Avatar-like world of growth and dreams and frolicking through temporary datasets. At the end of the day I can pretty much do the same thing withCREATE TEMPORARY TABLE
which is even better because it maintains relations. So I'd like to say something like 'don't waste your time with this crappy extension' but due to my limited experience, I won't. – Microscopium