I've put together a unit testing plugin for Symfony 1.4 that attempts to manage the database automatically, similarly to the way Django's test framework does it (destroy and rebuild the database between tests).
It makes sense to destroy and rebuild the database before the first test runs, as the schema could have changed during development, and it would be nothing short of horribly sadistic to make the developer keep his test database in sync with his models manually.
However, after the first test runs, I've found that it is usually faster just to delete all data, which would be a fairly simple task, except for the problem of foreign keys, which requires that the data be deleted in the correct order.
For MySQL, this isn't a problem; simply SET FOREIGN_KEY_CHECKS = 0
, and you can destroy referential integrity to your heart's content (until it comes time to SET FOREIGN_KEY_CHECKS = 1
, of course, but in this case, there would be no data left, so there's nothing for MySQL to complain about).
But this only works so long as the test database uses MySQL. For any other DBMS (esp. Sqlite), this will fail miserably.
Does Doctrine 1.2 provide a means for deleting all data in every table, or is there a way to "follow" relations (i.e., determine which tables have foreign keys and delete from them first)?