2008-12-18 17:08:11 +03:00
|
|
|
<?php
|
2009-01-04 19:15:32 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests\Mocks;
|
2008-12-18 17:08:11 +03:00
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* Mock class for UnitOfWork.
|
|
|
|
*/
|
2009-02-18 10:59:11 +03:00
|
|
|
class UnitOfWorkMock extends \Doctrine\ORM\UnitOfWork
|
|
|
|
{
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-12-18 17:08:11 +03:00
|
|
|
private $_mockDataChangeSets = array();
|
2012-12-14 22:55:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array|null
|
|
|
|
*/
|
2009-02-02 14:55:50 +03:00
|
|
|
private $_persisterMock;
|
|
|
|
|
|
|
|
/**
|
2012-12-14 22:55:28 +04:00
|
|
|
* {@inheritdoc}
|
2009-02-02 14:55:50 +03:00
|
|
|
*/
|
|
|
|
public function getEntityPersister($entityName)
|
|
|
|
{
|
|
|
|
return isset($this->_persisterMock[$entityName]) ?
|
|
|
|
$this->_persisterMock[$entityName] : parent::getEntityPersister($entityName);
|
|
|
|
}
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
/**
|
2012-12-14 22:55:28 +04:00
|
|
|
* {@inheritdoc}
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-02-18 10:59:11 +03:00
|
|
|
public function getEntityChangeSet($entity)
|
|
|
|
{
|
2009-01-03 22:50:13 +03:00
|
|
|
$oid = spl_object_hash($entity);
|
2008-12-18 17:08:11 +03:00
|
|
|
return isset($this->_mockDataChangeSets[$oid]) ?
|
2009-01-09 19:25:06 +03:00
|
|
|
$this->_mockDataChangeSets[$oid] : parent::getEntityChangeSet($entity);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* MOCK API */
|
|
|
|
|
2009-02-02 14:55:50 +03:00
|
|
|
/**
|
|
|
|
* Sets a (mock) persister for an entity class that will be returned when
|
|
|
|
* getEntityPersister() is invoked for that class.
|
|
|
|
*
|
2012-12-14 22:55:28 +04:00
|
|
|
* @param string $entityName
|
|
|
|
* @param \Doctrine\ORM\Persisters\BasicEntityPersister $persister
|
|
|
|
*
|
|
|
|
* @return void
|
2009-02-02 14:55:50 +03:00
|
|
|
*/
|
|
|
|
public function setEntityPersister($entityName, $persister)
|
|
|
|
{
|
|
|
|
$this->_persisterMock[$entityName] = $persister;
|
|
|
|
}
|
|
|
|
|
2012-12-14 22:55:28 +04:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2009-01-03 22:50:13 +03:00
|
|
|
public function setOriginalEntityData($entity, array $originalData)
|
|
|
|
{
|
|
|
|
$this->_originalEntityData[spl_object_hash($entity)] = $originalData;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
2012-12-14 22:55:28 +04:00
|
|
|
}
|