title: Strange Doctrine 2 behaviour with PHPUnit
body: <p>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:</p>
  
  <p>A setUp function:</p>
  
  <pre><code>public function setUp() 
  {
      $front = Zend_Controller_Front::getInstance();
      $bootstrap = $front-&gt;getParam("bootstrap");
  
      if(!$boostrap) {
          $application = Zend_Registry::get("application");
          $bootstrap = $application-&gt;getBootstrap();
      }
      $bootstrap-&gt;bootstrap('doctrine');
  
      $this-&gt;em   = $bootstrap-&gt;getResource('doctrine');
      $tool       = new \Doctrine\ORM\Tools\SchemaTool($this-&gt;em);
      $classes    = $this-&gt;em-&gt;getMetaDataFactory()-&gt;getAllMetaData();
  
      $tool-&gt;dropSchema($classes);
      $tool-&gt;createSchema($classes);
  
      parent::setUp();
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>I have two tests in one class that I am trying to run, with no dependencies. The first test inserts a record like so:</p>
  
  <pre><code>$value = 5;
  $model = new Model();
  $model-&gt;setUserId($rater-&gt;getId());
  $model-&gt;setValue($value);
  
  $this-&gt;em-&gt;persist($model);
  $this-&gt;em-&gt;flush();
  </code></pre>
  
  <p>So far, so good. I have a new record in the database with a value of 5.</p>
  
  <p>Onto the next test. This time I want to run:</p>
  
  <pre><code>$value = 3;
  $model = new Model();
  $model-&gt;setUserId($rater-&gt;getId());
  $model-&gt;setValue($value);
  
  $this-&gt;em-&gt;persist($model);
  $this-&gt;em-&gt;flush();
  </code></pre>
  
  <p>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.</p>
  
  <p>I've tried clearing various caches that I'm aware Doctrine can potentially make sure of, such as:</p>
  
  <pre><code>$cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
  $cacheDriver-&gt;deleteAll();
  </code></pre>
  
  <p>Can anybody suggest anything else I can try? Or is there some errant code somewhere in the way I have implemented Doctrine.</p>
  
  <p>Thanks</p>