2008-07-21 00:13:24 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'lib/mocks/Doctrine_EntityPersisterMock.php';
|
|
|
|
|
2008-09-12 17:16:05 +04:00
|
|
|
class Doctrine_EntityManagerMock extends Doctrine_ORM_EntityManager
|
2008-07-21 00:13:24 +04:00
|
|
|
{
|
|
|
|
private $_persisterMock;
|
2008-12-18 17:08:11 +03:00
|
|
|
private $_uowMock;
|
|
|
|
private $_idGenerators = array();
|
2008-07-21 00:13:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
public function getEntityPersister($entityName)
|
|
|
|
{
|
2008-12-18 17:08:11 +03:00
|
|
|
return isset($this->_persisterMock) ? $this->_persisterMock :
|
|
|
|
parent::getEntityPersister($entityName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
public function getUnitOfWork()
|
|
|
|
{
|
|
|
|
return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
|
2008-07-21 00:13:24 +04:00
|
|
|
}
|
2008-08-01 22:46:14 +04:00
|
|
|
|
|
|
|
/* Mock API */
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
public function setUnitOfWork($uow)
|
|
|
|
{
|
|
|
|
$this->_uowMock = $uow;
|
|
|
|
}
|
|
|
|
|
2008-08-01 22:46:14 +04:00
|
|
|
public function setEntityPersister($persister)
|
|
|
|
{
|
|
|
|
$this->_persisterMock = $persister;
|
|
|
|
}
|
2008-09-07 17:48:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock factory method.
|
|
|
|
*
|
|
|
|
* @param unknown_type $conn
|
|
|
|
* @param unknown_type $name
|
|
|
|
* @param Doctrine_Configuration $config
|
|
|
|
* @param Doctrine_EventManager $eventManager
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2008-12-18 17:21:21 +03:00
|
|
|
public static function create($conn, $name, Doctrine_ORM_Configuration $config = null,
|
2008-09-12 14:55:06 +04:00
|
|
|
Doctrine_Common_EventManager $eventManager = null)
|
2008-09-07 17:48:40 +04:00
|
|
|
{
|
|
|
|
if (is_null($config)) {
|
2008-12-18 17:21:21 +03:00
|
|
|
$config = new Doctrine_ORM_Configuration();
|
2008-09-07 17:48:40 +04:00
|
|
|
}
|
|
|
|
if (is_null($eventManager)) {
|
2008-09-12 14:55:06 +04:00
|
|
|
$eventManager = new Doctrine_Common_EventManager();
|
2008-09-07 17:48:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Doctrine_EntityManagerMock($conn, $name, $config, $eventManager);
|
|
|
|
}
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
public function setIdGenerator($className, $generator)
|
|
|
|
{
|
|
|
|
$this->_idGenerators[$className] = $generator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIdGenerator($className)
|
|
|
|
{
|
|
|
|
if (isset($this->_idGenerators[$className])) {
|
|
|
|
return $this->_idGenerators[$className];
|
|
|
|
}
|
|
|
|
return parent::getIdGenerator($className);
|
|
|
|
}
|
2008-07-21 00:13:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|