2008-07-20 20:13:24 +00:00
|
|
|
<?php
|
|
|
|
|
2009-01-22 19:38:10 +00:00
|
|
|
namespace Doctrine\Tests\Mocks;
|
2009-10-14 20:18:36 +00:00
|
|
|
|
2016-05-11 01:55:12 +07:00
|
|
|
use Doctrine\Common\EventManager;
|
|
|
|
use Doctrine\ORM\Configuration;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
2008-07-20 20:13:24 +00:00
|
|
|
|
2009-01-03 19:50:13 +00:00
|
|
|
/**
|
|
|
|
* Special EntityManager mock used for testing purposes.
|
|
|
|
*/
|
2016-05-11 01:55:12 +07:00
|
|
|
class EntityManagerMock extends EntityManager
|
2008-07-20 20:13:24 +00:00
|
|
|
{
|
2012-12-14 18:55:28 +00:00
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\UnitOfWork|null
|
|
|
|
*/
|
2008-12-18 14:08:11 +00:00
|
|
|
private $_uowMock;
|
2012-12-14 18:55:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\Proxy\ProxyFactory|null
|
|
|
|
*/
|
2009-07-20 12:05:19 +00:00
|
|
|
private $_proxyFactoryMock;
|
2012-12-14 18:55:28 +00:00
|
|
|
|
2008-12-18 14:08:11 +00:00
|
|
|
/**
|
2012-12-14 18:55:28 +00:00
|
|
|
* {@inheritdoc}
|
2008-12-18 14:08:11 +00:00
|
|
|
*/
|
|
|
|
public function getUnitOfWork()
|
|
|
|
{
|
|
|
|
return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
|
2008-07-20 20:13:24 +00:00
|
|
|
}
|
2011-12-19 22:56:19 +01: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.
|
|
|
|
*
|
2012-12-14 18:55:28 +00:00
|
|
|
* @param \Doctrine\ORM\UnitOfWork $uow
|
|
|
|
*
|
|
|
|
* @return void
|
2009-01-03 19:50:13 +00:00
|
|
|
*/
|
2008-12-18 14:08:11 +00:00
|
|
|
public function setUnitOfWork($uow)
|
|
|
|
{
|
|
|
|
$this->_uowMock = $uow;
|
|
|
|
}
|
2009-07-20 12:05:19 +00:00
|
|
|
|
2012-12-14 18:55:28 +00:00
|
|
|
/**
|
|
|
|
* @param \Doctrine\ORM\Proxy\ProxyFactory $proxyFactory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-07-20 12:05:19 +00:00
|
|
|
public function setProxyFactory($proxyFactory)
|
|
|
|
{
|
|
|
|
$this->_proxyFactoryMock = $proxyFactory;
|
|
|
|
}
|
|
|
|
|
2012-12-14 18:55:28 +00:00
|
|
|
/**
|
|
|
|
* @return \Doctrine\ORM\Proxy\ProxyFactory
|
|
|
|
*/
|
2009-07-20 12:05:19 +00:00
|
|
|
public function getProxyFactory()
|
|
|
|
{
|
|
|
|
return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory();
|
|
|
|
}
|
2011-12-19 22:56:19 +01:00
|
|
|
|
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
|
|
|
*
|
2012-12-14 18:55:28 +00:00
|
|
|
* {@inheritdoc}
|
2008-09-07 13:48:40 +00:00
|
|
|
*/
|
2016-05-11 01:55:12 +07:00
|
|
|
public static function create($conn, Configuration $config = null, EventManager $eventManager = null)
|
2008-09-07 13:48:40 +00:00
|
|
|
{
|
2014-07-30 16:54:24 -03:00
|
|
|
if (null === $config) {
|
2016-05-11 01:55:12 +07:00
|
|
|
$config = new Configuration();
|
2009-10-14 20:18:36 +00:00
|
|
|
$config->setProxyDir(__DIR__ . '/../Proxies');
|
|
|
|
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
2012-07-08 14:58:06 +02:00
|
|
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true));
|
2008-09-07 13:48:40 +00:00
|
|
|
}
|
2014-07-30 16:54:24 -03:00
|
|
|
if (null === $eventManager) {
|
2016-05-11 01:55:12 +07:00
|
|
|
$eventManager = new EventManager();
|
2008-09-07 13:48:40 +00:00
|
|
|
}
|
2011-12-19 22:56:19 +01:00
|
|
|
|
|
|
|
return new EntityManagerMock($conn, $config, $eventManager);
|
2008-09-07 13:48:40 +00:00
|
|
|
}
|
2009-07-20 12:05:19 +00:00
|
|
|
}
|