3 namespace Doctrine\Tests\Mocks;
6 * EntityPersister implementation used for mocking during tests.
8 class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
10 private $_inserts = array();
11 private $_updates = array();
12 private $_deletes = array();
13 private $_identityColumnValueCounter = 0;
14 private $_mockIdGeneratorType;
15 private $_postInsertIds = array();
16 private $existsCalled = false;
19 * @param <type> $entity
23 public function insert($entity)
25 $this->_inserts[] = $entity;
26 if ( ! is_null($this->_mockIdGeneratorType) && $this->_mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY
27 || $this->_class->isIdGeneratorIdentity()) {
28 $id = $this->_identityColumnValueCounter++;
29 $this->_postInsertIds[$id] = $entity;
35 public function addInsert($entity)
37 $this->_inserts[] = $entity;
38 if ( ! is_null($this->_mockIdGeneratorType) && $this->_mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY
39 || $this->_class->isIdGeneratorIdentity()) {
40 $id = $this->_identityColumnValueCounter++;
41 $this->_postInsertIds[$id] = $entity;
47 public function executeInserts()
49 return $this->_postInsertIds;
52 public function setMockIdGeneratorType($genType)
54 $this->_mockIdGeneratorType = $genType;
57 public function update($entity)
59 $this->_updates[] = $entity;
62 public function exists($entity, array $extraConditions = array())
64 $this->existsCalled = true;
67 public function delete($entity)
69 $this->_deletes[] = $entity;
72 public function getInserts()
74 return $this->_inserts;
77 public function getUpdates()
79 return $this->_updates;
82 public function getDeletes()
84 return $this->_deletes;
87 public function reset()
89 $this->existsCalled = false;
90 $this->_identityColumnValueCounter = 0;
91 $this->_inserts = array();
92 $this->_updates = array();
93 $this->_deletes = array();
96 public function isExistsCalled()
98 return $this->existsCalled;