2008-07-20 20:13:24 +00:00
|
|
|
<?php
|
|
|
|
|
2009-01-22 19:38:10 +00:00
|
|
|
namespace Doctrine\Tests\Mocks;
|
2008-07-20 20:13:24 +00:00
|
|
|
|
2009-01-03 19:50:13 +00:00
|
|
|
/**
|
|
|
|
* Special EntityManager mock used for testing purposes.
|
|
|
|
*/
|
2009-01-22 19:38:10 +00:00
|
|
|
class EntityManagerMock extends \Doctrine\ORM\EntityManager
|
2008-07-20 20:13:24 +00:00
|
|
|
{
|
2008-12-18 14:08:11 +00:00
|
|
|
private $_uowMock;
|
|
|
|
private $_idGenerators = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
public function getUnitOfWork()
|
|
|
|
{
|
|
|
|
return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
|
2008-07-20 20:13:24 +00:00
|
|
|
}
|
2008-08-01 18:46:14 +00:00
|
|
|
|
|
|
|
/* Mock API */
|
2008-12-18 14:08:11 +00:00
|
|
|
|
2009-01-03 19:50:13 +00:00
|
|
|
/**
|
|
|
|
* Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called.
|
|
|
|
*
|
|
|
|
* @param <type> $uow
|
|
|
|
*/
|
2008-12-18 14:08:11 +00:00
|
|
|
public function setUnitOfWork($uow)
|
|
|
|
{
|
|
|
|
$this->_uowMock = $uow;
|
|
|
|
}
|
2008-09-07 13:48:40 +00:00
|
|
|
|
|
|
|
/**
|
2009-01-03 19:50:13 +00:00
|
|
|
* Mock factory method to create an EntityManager.
|
2008-09-07 13:48:40 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $conn
|
|
|
|
* @param unknown_type $name
|
|
|
|
* @param Doctrine_Configuration $config
|
|
|
|
* @param Doctrine_EventManager $eventManager
|
2009-01-03 19:50:13 +00:00
|
|
|
* @return Doctrine\ORM\EntityManager
|
2008-09-07 13:48:40 +00:00
|
|
|
*/
|
2009-01-22 19:38:10 +00:00
|
|
|
public static function create($conn, $name, \Doctrine\ORM\Configuration $config = null,
|
2008-09-12 10:55:06 +00:00
|
|
|
Doctrine_Common_EventManager $eventManager = null)
|
2008-09-07 13:48:40 +00:00
|
|
|
{
|
|
|
|
if (is_null($config)) {
|
2009-01-22 19:38:10 +00:00
|
|
|
$config = new \Doctrine\ORM\Configuration();
|
2008-09-07 13:48:40 +00:00
|
|
|
}
|
|
|
|
if (is_null($eventManager)) {
|
2009-01-22 19:38:10 +00:00
|
|
|
$eventManager = new \Doctrine\Common\EventManager();
|
2008-09-07 13:48:40 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 19:38:10 +00:00
|
|
|
return new EntityManagerMock($conn, $name, $config, $eventManager);
|
2008-09-07 13:48:40 +00:00
|
|
|
}
|
2008-12-18 14:08:11 +00:00
|
|
|
|
|
|
|
public function setIdGenerator($className, $generator)
|
|
|
|
{
|
|
|
|
$this->_idGenerators[$className] = $generator;
|
|
|
|
}
|
|
|
|
|
2009-01-09 16:25:06 +00:00
|
|
|
/** @override */
|
2008-12-18 14:08:11 +00:00
|
|
|
public function getIdGenerator($className)
|
|
|
|
{
|
2009-01-22 19:38:10 +00:00
|
|
|
|
2008-12-18 14:08:11 +00:00
|
|
|
if (isset($this->_idGenerators[$className])) {
|
|
|
|
return $this->_idGenerators[$className];
|
|
|
|
}
|
2009-01-22 19:38:10 +00:00
|
|
|
|
2008-12-18 14:08:11 +00:00
|
|
|
return parent::getIdGenerator($className);
|
|
|
|
}
|
2008-07-20 20:13:24 +00:00
|
|
|
}
|
|
|
|
|