Hi,
I also thought about writing some kind of DB-mock for unittesting, but
soon gave up this idea, because I didn't see an easy way to do so. But
maybe I just didn't see something..
My approach now is to load a test-db containing only some "static"
content at the beginning and retrieving all empy tables:
// Determine empty tables (user-tables) and put their names in the registry
$usertables = array();
$tables = $db->listTables();
foreach ($tables as $table) {
if ($db->fetchOne('SELECT COUNT(1) FROM `' .$table . '`') == 0) {
$usertables[] = $table;
}
}
Zend_Registry::set('usertables',$usertables);
Then after each test (I think it should happen after a test, not
before..), I truncate those tables which were empty in the very
beginning:
/**
* Truncate all user-tables
*/
public static function clearDb() {
$usertables = Zend_Registry::get('usertables');
foreach ($usertables as $table) {
$db->query('TRUNCATE TABLE `' . $table . '`');
}
}
But I would also be interested in an easy way to write a db-mock..
Sincerely,
Reto Kaiser