66use Neusta \Pimcore \HttpCacheBundle \Cache \CacheTag ;
77use Neusta \Pimcore \HttpCacheBundle \Cache \CacheTags ;
88use Neusta \Pimcore \HttpCacheBundle \Element \ElementInvalidationEvent ;
9+ use Neusta \Pimcore \HttpCacheBundle \Element \ElementRepository ;
910use Neusta \Pimcore \HttpCacheBundle \Element \InvalidateElementListener ;
1011use PHPUnit \Framework \TestCase ;
1112use Pimcore \Event \Model \AssetEvent ;
@@ -33,13 +34,18 @@ final class InvalidateElementListenerTest extends TestCase
3334 /** @var ObjectProphecy<EventDispatcherInterface> */
3435 private $ eventDispatcher ;
3536
37+ /** @var ObjectProphecy<ElementRepository> */
38+ private $ elementRepository ;
39+
3640 protected function setUp (): void
3741 {
3842 $ this ->cacheInvalidator = $ this ->prophesize (CacheInvalidator::class);
3943 $ this ->eventDispatcher = $ this ->prophesize (EventDispatcherInterface::class);
44+ $ this ->elementRepository = $ this ->prophesize (ElementRepository::class);
4045 $ this ->invalidateElementListener = new InvalidateElementListener (
4146 $ this ->cacheInvalidator ->reveal (),
4247 $ this ->eventDispatcher ->reveal (),
48+ $ this ->elementRepository ->reveal (),
4349 );
4450
4551 $ this ->eventDispatcher ->dispatch (Argument::type (ElementInvalidationEvent::class))
@@ -109,7 +115,7 @@ public function onUpdate_should_invalidate_elements(ElementEventInterface $event
109115 /**
110116 * @test
111117 */
112- public function onUpdate_should_invalidate_dependent_elements_from_objects (): void
118+ public function onUpdate_should_invalidate_dependent_elements (): void
113119 {
114120 $ element = $ this ->prophesize (DataObject \TestDataObject::class);
115121 $ dependency = $ this ->prophesize (Dependency::class);
@@ -119,7 +125,8 @@ public function onUpdate_should_invalidate_dependent_elements_from_objects(): vo
119125 $ element ->getId ()->willReturn (42 );
120126 $ element ->getDependencies ()->willReturn ($ dependency ->reveal ());
121127 $ dependentElement ->getId ()->willReturn (23 );
122- $ dependency ->getRequiredBy ()->willReturn ([$ dependentElement ->reveal ()]);
128+ $ dependency ->getRequiredBy ()->willReturn ([['id ' => 23 , 'type ' => 'object ' ]]);
129+ $ this ->elementRepository ->findObject (23 )->willReturn ($ dependentElement ->reveal ());
123130
124131 $ this ->invalidateElementListener ->onUpdate ($ event );
125132
@@ -202,7 +209,7 @@ public function onDelete_should_invalidate_elements(ElementEventInterface $event
202209 /**
203210 * @test
204211 */
205- public function onDelete_should_invalidate_dependent_elements_from_objects (): void
212+ public function onDelete_should_invalidate_dependent_elements (): void
206213 {
207214 $ element = $ this ->prophesize (DataObject \TestDataObject::class);
208215 $ dependency = $ this ->prophesize (Dependency::class);
@@ -212,7 +219,8 @@ public function onDelete_should_invalidate_dependent_elements_from_objects(): vo
212219 $ element ->getId ()->willReturn (42 );
213220 $ element ->getDependencies ()->willReturn ($ dependency ->reveal ());
214221 $ dependentElement ->getId ()->willReturn (23 );
215- $ dependency ->getRequiredBy ()->willReturn ([$ dependentElement ->reveal ()]);
222+ $ dependency ->getRequiredBy ()->willReturn ([['id ' => 23 , 'type ' => 'object ' ]]);
223+ $ this ->elementRepository ->findObject (23 )->willReturn ($ dependentElement ->reveal ());
216224
217225 $ this ->invalidateElementListener ->onDelete ($ event );
218226
@@ -266,16 +274,19 @@ public function onDelete_should_invalidate_additional_tags_when_requested(Elemen
266274
267275 public function elementProvider (): iterable
268276 {
277+ $ dependency = $ this ->prophesize (Dependency::class);
278+
269279 $ asset = $ this ->prophesize (Asset::class);
270280 $ asset ->getId ()->willReturn (42 );
281+ $ asset ->getDependencies ()->willReturn ($ dependency ->reveal ());
271282 yield 'Asset ' => ['event ' => new AssetEvent ($ asset ->reveal ())];
272283
273284 $ document = $ this ->prophesize (Document::class);
274285 $ document ->getId ()->willReturn (42 );
286+ $ document ->getDependencies ()->willReturn ($ dependency ->reveal ());
275287 yield 'Document ' => ['event ' => new DocumentEvent ($ document ->reveal ())];
276288
277289 $ dataObject = $ this ->prophesize (DataObject::class);
278- $ dependency = $ this ->prophesize (Dependency::class);
279290 $ dataObject ->getId ()->willReturn (42 );
280291 $ dataObject ->getDependencies ()->willReturn ($ dependency ->reveal ());
281292 $ dependency ->getRequiredBy ()->willReturn ([]);
0 commit comments