. */ namespace Doctrine\Tests\Mocks; use Doctrine\ORM\Proxy\ProxyFactory; /** * Special EntityManager mock used for testing purposes. */ class EntityManagerMock extends \Doctrine\ORM\EntityManager { /** * @var \Doctrine\ORM\UnitOfWork|null */ private $_uowMock; /** * @var \Doctrine\ORM\Proxy\ProxyFactory|null */ private $_proxyFactoryMock; /** * @var array */ private $_idGenerators = array(); /** * {@inheritdoc} */ public function getUnitOfWork() { return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork(); } /* Mock API */ /** * Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called. * * @param \Doctrine\ORM\UnitOfWork $uow * * @return void */ public function setUnitOfWork($uow) { $this->_uowMock = $uow; } /** * @param \Doctrine\ORM\Proxy\ProxyFactory $proxyFactory * * @return void */ public function setProxyFactory($proxyFactory) { $this->_proxyFactoryMock = $proxyFactory; } /** * @return \Doctrine\ORM\Proxy\ProxyFactory */ public function getProxyFactory() { return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory(); } /** * Mock factory method to create an EntityManager. * * {@inheritdoc} */ public static function create($conn, \Doctrine\ORM\Configuration $config = null, \Doctrine\Common\EventManager $eventManager = null) { if (is_null($config)) { $config = new \Doctrine\ORM\Configuration(); $config->setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true)); } if (is_null($eventManager)) { $eventManager = new \Doctrine\Common\EventManager(); } return new EntityManagerMock($conn, $config, $eventManager); } /* public function setIdGenerator($className, $generator) { $this->_idGenerators[$className] = $generator; } */ /** @override */ /* public function getIdGenerator($className) { if (isset($this->_idGenerators[$className])) { return $this->_idGenerators[$className]; } return parent::getIdGenerator($className); } */ }