Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Mocks / EntityPersisterMock.php
1 <?php
2
3 namespace Doctrine\Tests\Mocks;
4
5 /**
6  * EntityPersister implementation used for mocking during tests.
7  */
8 class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister
9 {
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;
17
18     /**
19      * @param <type> $entity
20      * @return <type>
21      * @override
22      */
23     public function insert($entity)
24     {
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;
30             return $id;
31         }
32         return null;
33     }
34
35     public function addInsert($entity)
36     {
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;
42             return $id;
43         }
44         return null;
45     }
46
47     public function executeInserts()
48     {
49         return $this->_postInsertIds;
50     }
51
52     public function setMockIdGeneratorType($genType)
53     {
54         $this->_mockIdGeneratorType = $genType;
55     }
56
57     public function update($entity)
58     {
59         $this->_updates[] = $entity;
60     }
61
62     public function exists($entity, array $extraConditions = array())
63     {
64         $this->existsCalled = true;
65     }
66
67     public function delete($entity)
68     {
69         $this->_deletes[] = $entity;
70     }
71
72     public function getInserts()
73     {
74         return $this->_inserts;
75     }
76
77     public function getUpdates()
78     {
79         return $this->_updates;
80     }
81
82     public function getDeletes()
83     {
84         return $this->_deletes;
85     }
86
87     public function reset()
88     {
89         $this->existsCalled = false;
90         $this->_identityColumnValueCounter = 0;
91         $this->_inserts = array();
92         $this->_updates = array();
93         $this->_deletes = array();
94     }
95
96     public function isExistsCalled()
97     {
98         return $this->existsCalled;
99     }
100 }