title: How to create a mock object of a doctrine entity?
body: <p>I'm trying to write a unit test with phpunit for a model that uses doctrine 2. I want to mock the doctrine entities but I really don't have a clue of how to do this. Can anyone explain to me how I need to do this? I'm using Zend Framework.</p>
  
  <p><strong>The model that needs to be tested</strong></p>
  
  <pre><code>class Country extends App_Model
  {
      public function findById($id)
      {
          try {
              return $this-&gt;_em-&gt;find('Entities\Country', $id);
          } catch (\Doctrine\ORM\ORMException $e) {
              return NULL;
          }
      }
  
      public function findByIso($iso)
      {
          try {
              return $this-&gt;_em-&gt;getRepository('Entities\Country')-&gt;findOneByIso($iso);
          } catch (\Doctrine\ORM\ORMException $e) {
              return NULL;
          }
      }
  }
  </code></pre>
  
  <p><strong>Bootstrap.php</strong></p>
  
  <pre><code>protected function _initDoctrine()
  {
      Some configuration of doctrine
      ... 
      // Create EntityManager
      $em = EntityManager::create($connectionOptions, $dcConf);
      Zend_Registry::set('EntityManager', $em);
  }
  </code></pre>
  
  <p><strong>Extended model</strong></p>
  
  <pre><code>class App_Model
  {
      // Doctrine 2.0 entity manager
      protected $_em;
  
      public function __construct()
      {
          $this-&gt;_em = Zend_Registry::get('EntityManager');
      }
  }
  </code></pre>