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
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of Doctrine_UnitOfWorkMock
|
|
|
|
*
|
|
|
|
* @author robo
|
|
|
|
*/
|
2009-01-22 22:38:10 +03:00
|
|
|
class UnitOfWorkMock extends \Doctrine\ORM\UnitOfWork {
|
2008-12-18 17:08:11 +03:00
|
|
|
private $_mockDataChangeSets = array();
|
2009-02-02 14:55:50 +03:00
|
|
|
private $_persisterMock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
public function getEntityPersister($entityName)
|
|
|
|
{
|
|
|
|
return isset($this->_persisterMock[$entityName]) ?
|
|
|
|
$this->_persisterMock[$entityName] : parent::getEntityPersister($entityName);
|
|
|
|
}
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param <type> $entity
|
|
|
|
* @override
|
|
|
|
*/
|
2009-01-09 19:25:06 +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.
|
|
|
|
*
|
|
|
|
* @param <type> $entityName
|
|
|
|
* @param <type> $persister
|
|
|
|
*/
|
|
|
|
public function setEntityPersister($entityName, $persister)
|
|
|
|
{
|
|
|
|
$this->_persisterMock[$entityName] = $persister;
|
|
|
|
}
|
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
public function setDataChangeSet($entity, array $mockChangeSet) {
|
2009-01-03 22:50:13 +03:00
|
|
|
$this->_mockDataChangeSets[spl_object_hash($entity)] = $mockChangeSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEntityState($entity, $state)
|
|
|
|
{
|
|
|
|
$this->_entityStates[spl_object_hash($entity)] = $state;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOriginalEntityData($entity, array $originalData)
|
|
|
|
{
|
|
|
|
$this->_originalEntityData[spl_object_hash($entity)] = $originalData;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|