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;
|
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
|
|
|
{
|
2008-12-18 17:08:11 +03:00
|
|
|
private $_uowMock;
|
|
|
|
private $_idGenerators = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
2009-01-03 22:50:13 +03:00
|
|
|
/**
|
|
|
|
* Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called.
|
|
|
|
*
|
|
|
|
* @param <type> $uow
|
|
|
|
*/
|
2008-12-18 17:08:11 +03:00
|
|
|
public function setUnitOfWork($uow)
|
|
|
|
{
|
|
|
|
$this->_uowMock = $uow;
|
|
|
|
}
|
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
|
|
|
*
|
|
|
|
* @param unknown_type $conn
|
|
|
|
* @param unknown_type $name
|
|
|
|
* @param Doctrine_Configuration $config
|
|
|
|
* @param Doctrine_EventManager $eventManager
|
2009-01-03 22:50:13 +03:00
|
|
|
* @return Doctrine\ORM\EntityManager
|
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();
|
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
|
|
|
}
|
|
|
|
|
2009-02-17 14:02:11 +03: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];
|
|
|
|
}
|
2009-01-22 22:38:10 +03:00
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
return parent::getIdGenerator($className);
|
|
|
|
}
|
2009-03-30 23:43:05 +04:00
|
|
|
*/
|
2009-02-18 10:59:11 +03:00
|
|
|
}
|