I have a Zend Framework application (version 1.11) that uses Doctrine 2. I've got PHPUnit set up to run tests on my models and forms and whatnot. The tests work great, but there's one problem: they leave the test data in the database once they are done. Here's a basic sample of one of my tests:
class VisaTypeEntityTest extends ModelTestCase
{
public function testCanSaveAndRetrieveVisaType()
{
$addVisaType = new \Entities\VisaTypes();
$addVisaType->setEnglishName('Test Visa Type')
->setJapaneseName('試し')
->setKanaName('タメシ')
->setDescription('Description of the test visa type');
$this->em->persist($addVisaType);
$this->em->flush();
$getVisaType = $this->em->getRepository('\Entities\VisaTypes')
->findOneByEnglishName('Test Visa Type');
$this->assertEquals('Test Visa Type', $getVisaType->getEnglishName());
}
}
Obviously the data has to actually be entered into the database in order to make sure everything is kosher. But I don't want all the test data gumming up the database every time I run a test, nor do I want to go and manually remove it.
Is there something I can do, such as using the tearDown() method to get rid of the test data once the test is complete? And if so, is it possible to "roll back" the auto increments in the tables' id fields to what they were beforehand? I know it really shouldn't matter if there are gaps between ids, but if there is some way to get Doctrine to reset the auto increment value that would be great.