I'm trying to set up my PHPUnit tests with Doctrine 2 ORM. However, I am getting strange issues which I can only assume are down to some sort of caching (on Doctrine's end), which I cannot figure out how to overcome. This is what I've got:
A setUp function:
public function setUp()
{
$front = Zend_Controller_Front::getInstance();
$bootstrap = $front->getParam("bootstrap");
if(!$boostrap) {
$application = Zend_Registry::get("application");
$bootstrap = $application->getBootstrap();
}
$bootstrap->bootstrap('doctrine');
$this->em = $bootstrap->getResource('doctrine');
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
$classes = $this->em->getMetaDataFactory()->getAllMetaData();
$tool->dropSchema($classes);
$tool->createSchema($classes);
parent::setUp();
}
This basically aims to reset the doctrine instance for every test. I haven't got a tearDown() function as, at the moment, this takes care of resetting the schema as illustrated. I should mention here that I am using SQLite.
I have two tests in one class that I am trying to run, with no dependencies. The first test inserts a record like so:
$value = 5;
$model = new Model();
$model->setUserId($rater->getId());
$model->setValue($value);
$this->em->persist($model);
$this->em->flush();
So far, so good. I have a new record in the database with a value of 5.
Onto the next test. This time I want to run:
$value = 3;
$model = new Model();
$model->setUserId($rater->getId());
$model->setValue($value);
$this->em->persist($model);
$this->em->flush();
Dumping all records from the relevant table gives me one result; a record with a value of 5 again. In other words, the second test is taking the $value from the first test. I've double checked by dumping all records at the start of the second test and this returns nothing. It seems there are some caching issues in Doctrine somewhere that I'm not aware of.
I've tried clearing various caches that I'm aware Doctrine can potentially make sure of, such as:
$cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
$cacheDriver->deleteAll();
Can anybody suggest anything else I can try? Or is there some errant code somewhere in the way I have implemented Doctrine.
Thanks