@@ 54-72 (lines=19) @@ | ||
51 | $this->_em->find(CmsUser::class, $this->userId); |
|
52 | } |
|
53 | ||
54 | public function testLoadedEntityUsingQueryShouldTriggerEvent() |
|
55 | { |
|
56 | $mockListener = $this->createMock(PostLoadListener::class); |
|
57 | ||
58 | // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser |
|
59 | $mockListener |
|
60 | ->expects($this->exactly(2)) |
|
61 | ->method('postLoad') |
|
62 | ->will($this->returnValue(true)); |
|
63 | ||
64 | $eventManager = $this->_em->getEventManager(); |
|
65 | ||
66 | $eventManager->addEventListener([Events::postLoad], $mockListener); |
|
67 | ||
68 | $query = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id'); |
|
69 | ||
70 | $query->setParameter('id', $this->userId); |
|
71 | $query->getResult(); |
|
72 | } |
|
73 | ||
74 | public function testLoadedAssociationToOneShouldTriggerEvent() |
|
75 | { |
|
@@ 74-92 (lines=19) @@ | ||
71 | $query->getResult(); |
|
72 | } |
|
73 | ||
74 | public function testLoadedAssociationToOneShouldTriggerEvent() |
|
75 | { |
|
76 | $mockListener = $this->createMock(PostLoadListener::class); |
|
77 | ||
78 | // CmsUser (root), CmsAddress (ToOne inverse side), CmsEmail (joined association) |
|
79 | $mockListener |
|
80 | ->expects($this->exactly(3)) |
|
81 | ->method('postLoad') |
|
82 | ->will($this->returnValue(true)); |
|
83 | ||
84 | $eventManager = $this->_em->getEventManager(); |
|
85 | ||
86 | $eventManager->addEventListener([Events::postLoad], $mockListener); |
|
87 | ||
88 | $query = $this->_em->createQuery('SELECT u, e FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e WHERE u.id = :id'); |
|
89 | ||
90 | $query->setParameter('id', $this->userId); |
|
91 | $query->getResult(); |
|
92 | } |
|
93 | ||
94 | public function testLoadedAssociationToManyShouldTriggerEvent() |
|
95 | { |
|
@@ 94-112 (lines=19) @@ | ||
91 | $query->getResult(); |
|
92 | } |
|
93 | ||
94 | public function testLoadedAssociationToManyShouldTriggerEvent() |
|
95 | { |
|
96 | $mockListener = $this->createMock(PostLoadListener::class); |
|
97 | ||
98 | // CmsUser (root), CmsAddress (ToOne inverse side), 2 CmsPhonenumber (joined association) |
|
99 | $mockListener |
|
100 | ->expects($this->exactly(4)) |
|
101 | ->method('postLoad') |
|
102 | ->will($this->returnValue(true)); |
|
103 | ||
104 | $eventManager = $this->_em->getEventManager(); |
|
105 | ||
106 | $eventManager->addEventListener([Events::postLoad], $mockListener); |
|
107 | ||
108 | $query = $this->_em->createQuery('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p WHERE u.id = :id'); |
|
109 | ||
110 | $query->setParameter('id', $this->userId); |
|
111 | $query->getResult(); |
|
112 | } |
|
113 | ||
114 | public function testLoadedProxyEntityShouldTriggerEvent() |
|
115 | { |
|
@@ 145-164 (lines=20) @@ | ||
142 | $userProxy->getName(); |
|
143 | } |
|
144 | ||
145 | public function testLoadedProxyPartialShouldTriggerEvent() |
|
146 | { |
|
147 | $eventManager = $this->_em->getEventManager(); |
|
148 | ||
149 | // Should not be invoked during getReference call |
|
150 | $mockListener = $this->createMock(PostLoadListener::class); |
|
151 | ||
152 | // CmsUser (partially loaded), CmsAddress (inverse ToOne), 2 CmsPhonenumber |
|
153 | $mockListener |
|
154 | ->expects($this->exactly(4)) |
|
155 | ->method('postLoad') |
|
156 | ->will($this->returnValue(true)); |
|
157 | ||
158 | $eventManager->addEventListener([Events::postLoad], $mockListener); |
|
159 | ||
160 | $query = $this->_em->createQuery('SELECT PARTIAL u.{id, name}, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p WHERE u.id = :id'); |
|
161 | ||
162 | $query->setParameter('id', $this->userId); |
|
163 | $query->getResult(); |
|
164 | } |
|
165 | ||
166 | public function testLoadedProxyAssociationToOneShouldTriggerEvent() |
|
167 | { |
|
@@ 166-185 (lines=20) @@ | ||
163 | $query->getResult(); |
|
164 | } |
|
165 | ||
166 | public function testLoadedProxyAssociationToOneShouldTriggerEvent() |
|
167 | { |
|
168 | $user = $this->_em->find(CmsUser::class, $this->userId); |
|
169 | ||
170 | $mockListener = $this->createMock(PostLoadListener::class); |
|
171 | ||
172 | // CmsEmail (proxy) |
|
173 | $mockListener |
|
174 | ->expects($this->exactly(1)) |
|
175 | ->method('postLoad') |
|
176 | ->will($this->returnValue(true)); |
|
177 | ||
178 | $eventManager = $this->_em->getEventManager(); |
|
179 | ||
180 | $eventManager->addEventListener([Events::postLoad], $mockListener); |
|
181 | ||
182 | $emailProxy = $user->getEmail(); |
|
183 | ||
184 | $emailProxy->getEmail(); |
|
185 | } |
|
186 | ||
187 | public function testLoadedProxyAssociationToManyShouldTriggerEvent() |
|
188 | { |
|
@@ 187-206 (lines=20) @@ | ||
184 | $emailProxy->getEmail(); |
|
185 | } |
|
186 | ||
187 | public function testLoadedProxyAssociationToManyShouldTriggerEvent() |
|
188 | { |
|
189 | $user = $this->_em->find(CmsUser::class, $this->userId); |
|
190 | ||
191 | $mockListener = $this->createMock(PostLoadListener::class); |
|
192 | ||
193 | // 2 CmsPhonenumber (proxy) |
|
194 | $mockListener |
|
195 | ->expects($this->exactly(2)) |
|
196 | ->method('postLoad') |
|
197 | ->will($this->returnValue(true)); |
|
198 | ||
199 | $eventManager = $this->_em->getEventManager(); |
|
200 | ||
201 | $eventManager->addEventListener([Events::postLoad], $mockListener); |
|
202 | ||
203 | $phonenumbersCol = $user->getPhonenumbers(); |
|
204 | ||
205 | $phonenumbersCol->first(); |
|
206 | } |
|
207 | ||
208 | /** |
|
209 | * @group DDC-3005 |