How to create a mock object of a doctrine entity?

Kerfur

New Member
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.The model that needs to be tested\[code\]class Country extends App_Model{ public function findById($id) { try { return $this->_em->find('Entities\Country', $id); } catch (\Doctrine\ORM\ORMException $e) { return NULL; } } public function findByIso($iso) { try { return $this->_em->getRepository('Entities\Country')->findOneByIso($iso); } catch (\Doctrine\ORM\ORMException $e) { return NULL; } }}\[/code\]Bootstrap.php\[code\]protected function _initDoctrine(){ Some configuration of doctrine ... // Create EntityManager $em = EntityManager::create($connectionOptions, $dcConf); Zend_Registry::set('EntityManager', $em);}\[/code\]Extended model\[code\]class App_Model{ // Doctrine 2.0 entity manager protected $_em; public function __construct() { $this->_em = Zend_Registry::get('EntityManager'); }}\[/code\]
 
Back
Top