2008-07-21 00:13:24 +04:00
|
|
|
<?php
|
2009-02-05 20:34:44 +03:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
2008-07-21 00:13:24 +04:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests\Mocks;
|
2009-10-15 00:18:36 +04:00
|
|
|
|
2009-07-20 16:05:19 +04:00
|
|
|
use Doctrine\ORM\Proxy\ProxyFactory;
|
2008-07-21 00:13:24 +04:00
|
|
|
|
2009-01-03 22:50:13 +03:00
|
|
|
/**
|
|
|
|
* Special EntityManager mock used for testing purposes.
|
|
|
|
*/
|
2009-01-22 22:38:10 +03:00
|
|
|
class EntityManagerMock extends \Doctrine\ORM\EntityManager
|
2008-07-21 00:13:24 +04:00
|
|
|
{
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\UnitOfWork|null
|
|
|
|
*/
|
2008-12-18 17:08:11 +03:00
|
|
|
private $_uowMock;
|
2012-12-14 22:55:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\Proxy\ProxyFactory|null
|
|
|
|
*/
|
2009-07-20 16:05:19 +04:00
|
|
|
private $_proxyFactoryMock;
|
2012-12-14 22:55:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-12-18 17:08:11 +03:00
|
|
|
private $_idGenerators = array();
|
|
|
|
|
|
|
|
/**
|
2012-12-14 22:55:28 +04:00
|
|
|
* {@inheritdoc}
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function getUnitOfWork()
|
|
|
|
{
|
|
|
|
return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
|
2008-07-21 00:13:24 +04:00
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2008-08-01 22:46:14 +04:00
|
|
|
/* Mock API */
|
2008-12-18 17:08:11 +03:00
|
|
|
|
2009-01-03 22:50:13 +03:00
|
|
|
/**
|
|
|
|
* Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called.
|
|
|
|
*
|
2012-12-14 22:55:28 +04:00
|
|
|
* @param \Doctrine\ORM\UnitOfWork $uow
|
|
|
|
*
|
|
|
|
* @return void
|
2009-01-03 22:50:13 +03:00
|
|
|
*/
|
2008-12-18 17:08:11 +03:00
|
|
|
public function setUnitOfWork($uow)
|
|
|
|
{
|
|
|
|
$this->_uowMock = $uow;
|
|
|
|
}
|
2009-07-20 16:05:19 +04:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* @param \Doctrine\ORM\Proxy\ProxyFactory $proxyFactory
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-07-20 16:05:19 +04:00
|
|
|
public function setProxyFactory($proxyFactory)
|
|
|
|
{
|
|
|
|
$this->_proxyFactoryMock = $proxyFactory;
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* @return \Doctrine\ORM\Proxy\ProxyFactory
|
|
|
|
*/
|
2009-07-20 16:05:19 +04:00
|
|
|
public function getProxyFactory()
|
|
|
|
{
|
|
|
|
return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory();
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2008-09-07 17:48:40 +04:00
|
|
|
/**
|
2009-01-03 22:50:13 +03:00
|
|
|
* Mock factory method to create an EntityManager.
|
2008-09-07 17:48:40 +04:00
|
|
|
*
|
2012-12-14 22:55:28 +04:00
|
|
|
* {@inheritdoc}
|
2008-09-07 17:48:40 +04:00
|
|
|
*/
|
2009-02-17 14:02:11 +03:00
|
|
|
public static function create($conn, \Doctrine\ORM\Configuration $config = null,
|
|
|
|
\Doctrine\Common\EventManager $eventManager = null)
|
2008-09-07 17:48:40 +04:00
|
|
|
{
|
|
|
|
if (is_null($config)) {
|
2009-01-22 22:38:10 +03:00
|
|
|
$config = new \Doctrine\ORM\Configuration();
|
2009-10-15 00:18:36 +04:00
|
|
|
$config->setProxyDir(__DIR__ . '/../Proxies');
|
|
|
|
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
2012-07-08 16:58:06 +04:00
|
|
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true));
|
2008-09-07 17:48:40 +04:00
|
|
|
}
|
|
|
|
if (is_null($eventManager)) {
|
2009-01-22 22:38:10 +03:00
|
|
|
$eventManager = new \Doctrine\Common\EventManager();
|
2008-09-07 17:48:40 +04:00
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
|
|
|
return new EntityManagerMock($conn, $config, $eventManager);
|
2008-09-07 17:48:40 +04:00
|
|
|
}
|
2009-03-30 23:43:05 +04:00
|
|
|
/*
|
2008-12-18 17:08:11 +03:00
|
|
|
public function setIdGenerator($className, $generator)
|
|
|
|
{
|
|
|
|
$this->_idGenerators[$className] = $generator;
|
|
|
|
}
|
2009-03-30 23:43:05 +04:00
|
|
|
*/
|
2009-01-09 19:25:06 +03:00
|
|
|
/** @override */
|
2009-03-30 23:43:05 +04:00
|
|
|
/* public function getIdGenerator($className)
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-01-22 22:38:10 +03:00
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
if (isset($this->_idGenerators[$className])) {
|
|
|
|
return $this->_idGenerators[$className];
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
return parent::getIdGenerator($className);
|
|
|
|
}
|
2009-03-30 23:43:05 +04:00
|
|
|
*/
|
2009-07-20 16:05:19 +04:00
|
|
|
}
|