UnitOfWorkMock.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Doctrine\Tests\Mocks;
  3. class UnitOfWorkMock extends \Doctrine\ORM\UnitOfWork
  4. {
  5. private $_mockDataChangeSets = array();
  6. private $_persisterMock;
  7. /**
  8. * @override
  9. */
  10. public function getEntityPersister($entityName)
  11. {
  12. return isset($this->_persisterMock[$entityName]) ?
  13. $this->_persisterMock[$entityName] : parent::getEntityPersister($entityName);
  14. }
  15. /**
  16. * @param <type> $entity
  17. * @override
  18. */
  19. public function getEntityChangeSet($entity)
  20. {
  21. $oid = spl_object_hash($entity);
  22. return isset($this->_mockDataChangeSets[$oid]) ?
  23. $this->_mockDataChangeSets[$oid] : parent::getEntityChangeSet($entity);
  24. }
  25. /* MOCK API */
  26. /**
  27. * Sets a (mock) persister for an entity class that will be returned when
  28. * getEntityPersister() is invoked for that class.
  29. *
  30. * @param <type> $entityName
  31. * @param <type> $persister
  32. */
  33. public function setEntityPersister($entityName, $persister)
  34. {
  35. $this->_persisterMock[$entityName] = $persister;
  36. }
  37. public function setDataChangeSet($entity, array $mockChangeSet)
  38. {
  39. $this->_mockDataChangeSets[spl_object_hash($entity)] = $mockChangeSet;
  40. }
  41. public function setEntityState($entity, $state)
  42. {
  43. $this->_entityStates[spl_object_hash($entity)] = $state;
  44. }
  45. public function setOriginalEntityData($entity, array $originalData)
  46. {
  47. $this->_originalEntityData[spl_object_hash($entity)] = $originalData;
  48. }
  49. }