@@ -102,6 +102,9 @@ public function testOnFlush(): void
102
102
$ listener = new PurgeHttpCacheListener ($ purgerProphecy ->reveal (), $ iriConverterProphecy ->reveal (), $ resourceClassResolverProphecy ->reveal (), $ propertyAccessorProphecy ->reveal ());
103
103
$ listener ->onFlush ($ eventArgs );
104
104
$ listener ->postFlush ();
105
+
106
+ $ iriConverterProphecy ->getIriFromResource (Argument::type (Dummy::class), UrlGeneratorInterface::ABS_PATH , new GetCollection ())->shouldHaveBeenCalled ();
107
+ $ iriConverterProphecy ->getIriFromResource (Argument::type (DummyNoGetOperation::class), UrlGeneratorInterface::ABS_PATH , new GetCollection ())->shouldHaveBeenCalled ();
105
108
}
106
109
107
110
public function testPreUpdate (): void
@@ -172,14 +175,17 @@ public function testNothingToPurge(): void
172
175
public function testNotAResourceClass (): void
173
176
{
174
177
$ containNonResource = new ContainNonResource ();
175
- $ nonResource = new NotAResource ('foo ' , 'bar ' );
178
+ $ nonResource1 = new NotAResource ('foo ' , 'bar ' );
179
+ $ nonResource2 = new NotAResource ('baz ' , 'qux ' );
180
+ $ collectionOfNotAResource = [$ nonResource1 , $ nonResource2 ];
176
181
177
182
$ purgerProphecy = $ this ->prophesize (PurgerInterface::class);
178
- $ purgerProphecy ->purge ([])->shouldNotBeCalled ();
183
+ $ purgerProphecy ->purge ([' /dummies ' ])->shouldBeCalled ();
179
184
180
185
$ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
181
- $ iriConverterProphecy ->getIriFromResource (Argument::type (ContainNonResource::class), UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' );
182
- $ iriConverterProphecy ->getIriFromResource ($ nonResource )->willThrow (new InvalidArgumentException ())->shouldBeCalled ();
186
+ $ iriConverterProphecy ->getIriFromResource (Argument::type (ContainNonResource::class), UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' )->shouldBeCalled ();
187
+ $ iriConverterProphecy ->getIriFromResource ($ nonResource1 )->willThrow (new InvalidArgumentException ())->shouldBeCalled ();
188
+ $ iriConverterProphecy ->getIriFromResource ($ nonResource2 )->willThrow (new InvalidArgumentException ())->shouldBeCalled ();
183
189
184
190
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
185
191
$ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true )->shouldBeCalled ();
@@ -203,11 +209,59 @@ public function testNotAResourceClass(): void
203
209
204
210
$ propertyAccessorProphecy = $ this ->prophesize (PropertyAccessorInterface::class);
205
211
$ propertyAccessorProphecy ->isReadable (Argument::type (ContainNonResource::class), 'notAResource ' )->willReturn (true );
206
- $ propertyAccessorProphecy ->isReadable (Argument::type (ContainNonResource::class), 'collectionOfNotAResource ' )->willReturn (false );
207
- $ propertyAccessorProphecy ->getValue (Argument::type (ContainNonResource::class), 'notAResource ' )->shouldBeCalled ()->willReturn ($ nonResource );
208
- $ propertyAccessorProphecy ->getValue (Argument::type (ContainNonResource::class), 'collectionOfNotAResource ' )->shouldNotBeCalled ( );
212
+ $ propertyAccessorProphecy ->isReadable (Argument::type (ContainNonResource::class), 'collectionOfNotAResource ' )->willReturn (true );
213
+ $ propertyAccessorProphecy ->getValue (Argument::type (ContainNonResource::class), 'notAResource ' )->shouldBeCalled ()->willReturn ($ nonResource1 );
214
+ $ propertyAccessorProphecy ->getValue (Argument::type (ContainNonResource::class), 'collectionOfNotAResource ' )->shouldBeCalled ()-> willReturn ( $ collectionOfNotAResource );
209
215
210
216
$ listener = new PurgeHttpCacheListener ($ purgerProphecy ->reveal (), $ iriConverterProphecy ->reveal (), $ resourceClassResolverProphecy ->reveal (), $ propertyAccessorProphecy ->reveal ());
211
217
$ listener ->onFlush ($ eventArgs );
218
+ $ listener ->postFlush ();
219
+ }
220
+
221
+ public function testAddTagsForCollection (): void
222
+ {
223
+ $ dummy1 = new Dummy ();
224
+ $ dummy1 ->setId (1 );
225
+ $ dummy2 = new Dummy ();
226
+ $ dummy2 ->setId (2 );
227
+ $ collection = [$ dummy1 , $ dummy2 ];
228
+
229
+ $ purgerProphecy = $ this ->prophesize (PurgerInterface::class);
230
+ $ purgerProphecy ->purge (['/dummies ' , '/dummies/1 ' , '/dummies/2 ' ])->shouldBeCalled ();
231
+
232
+ $ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
233
+ $ iriConverterProphecy ->getIriFromResource (Argument::type (Dummy::class), UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' )->shouldBeCalled ();
234
+ $ iriConverterProphecy ->getIriFromResource ($ dummy1 )->willReturn ('/dummies/1 ' )->shouldBeCalled ();
235
+ $ iriConverterProphecy ->getIriFromResource ($ dummy2 )->willReturn ('/dummies/2 ' )->shouldBeCalled ();
236
+
237
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
238
+ $ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true )->shouldBeCalled ();
239
+
240
+ $ dummyWithCollection = new Dummy ();
241
+ $ dummyWithCollection ->setId (3 );
242
+
243
+ $ uowProphecy = $ this ->prophesize (UnitOfWork::class);
244
+ $ uowProphecy ->getScheduledEntityInsertions ()->willReturn ([$ dummyWithCollection ])->shouldBeCalled ();
245
+ $ uowProphecy ->getScheduledEntityUpdates ()->willReturn ([])->shouldBeCalled ();
246
+ $ uowProphecy ->getScheduledEntityDeletions ()->willReturn ([])->shouldBeCalled ();
247
+
248
+ $ emProphecy = $ this ->prophesize (EntityManagerInterface::class);
249
+ $ emProphecy ->getUnitOfWork ()->willReturn ($ uowProphecy ->reveal ())->shouldBeCalled ();
250
+
251
+ $ dummyClassMetadata = new ClassMetadata (Dummy::class);
252
+ // @phpstan-ignore-next-line
253
+ $ dummyClassMetadata ->associationMappings = [
254
+ 'relatedDummies ' => ['targetEntity ' => Dummy::class],
255
+ ];
256
+ $ emProphecy ->getClassMetadata (Dummy::class)->willReturn ($ dummyClassMetadata )->shouldBeCalled ();
257
+ $ eventArgs = new OnFlushEventArgs ($ emProphecy ->reveal ());
258
+
259
+ $ propertyAccessorProphecy = $ this ->prophesize (PropertyAccessorInterface::class);
260
+ $ propertyAccessorProphecy ->isReadable (Argument::type (Dummy::class), 'relatedDummies ' )->willReturn (true );
261
+ $ propertyAccessorProphecy ->getValue (Argument::type (Dummy::class), 'relatedDummies ' )->willReturn ($ collection )->shouldBeCalled ();
262
+
263
+ $ listener = new PurgeHttpCacheListener ($ purgerProphecy ->reveal (), $ iriConverterProphecy ->reveal (), $ resourceClassResolverProphecy ->reveal (), $ propertyAccessorProphecy ->reveal ());
264
+ $ listener ->onFlush ($ eventArgs );
265
+ $ listener ->postFlush ();
212
266
}
213
267
}
0 commit comments