@@ -65,19 +65,16 @@ public function testOnFlush(): void
65
65
$ purgerProphecy ->purge (['/dummies ' , '/dummies/1 ' , '/dummies/2 ' , '/dummies/3 ' , '/dummies/4 ' ])->shouldBeCalled ();
66
66
67
67
$ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
68
- $ iriConverterProphecy ->getIriFromResource (Dummy::class, UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' )->shouldBeCalled ();
69
- $ iriConverterProphecy ->getIriFromResource (DummyNoGetOperation::class, UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willThrow (new InvalidArgumentException ())->shouldBeCalled ();
68
+ $ iriConverterProphecy ->getIriFromResource (Argument::type (Dummy::class), UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' )->shouldBeCalled ();
70
69
$ iriConverterProphecy ->getIriFromResource ($ toUpdate1 )->willReturn ('/dummies/1 ' )->shouldBeCalled ();
71
70
$ iriConverterProphecy ->getIriFromResource ($ toUpdate2 )->willReturn ('/dummies/2 ' )->shouldBeCalled ();
72
71
$ iriConverterProphecy ->getIriFromResource ($ toDelete1 )->willReturn ('/dummies/3 ' )->shouldBeCalled ();
73
72
$ iriConverterProphecy ->getIriFromResource ($ toDelete2 )->willReturn ('/dummies/4 ' )->shouldBeCalled ();
74
- $ iriConverterProphecy ->getIriFromResource ($ toDeleteNoPurge )-> shouldNotBeCalled ();
73
+ $ iriConverterProphecy ->getIriFromResource (Argument:: type (DummyNoGetOperation::class), UrlGeneratorInterface:: ABS_PATH , new GetCollection ())-> willThrow ( new InvalidArgumentException ())-> shouldBeCalled ();
75
74
$ iriConverterProphecy ->getIriFromResource (Argument::any ())->willThrow (new ItemNotFoundException ());
76
75
77
76
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
78
77
$ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true )->shouldBeCalled ();
79
- $ resourceClassResolverProphecy ->getResourceClass (Argument::type (Dummy::class))->willReturn (Dummy::class)->shouldBeCalled ();
80
- $ resourceClassResolverProphecy ->getResourceClass (Argument::type (DummyNoGetOperation::class))->willReturn (DummyNoGetOperation::class)->shouldBeCalled ();
81
78
82
79
$ uowProphecy = $ this ->prophesize (UnitOfWork::class);
83
80
$ uowProphecy ->getScheduledEntityInsertions ()->willReturn ([$ toInsert1 , $ toInsert2 ])->shouldBeCalled ();
@@ -105,6 +102,9 @@ public function testOnFlush(): void
105
102
$ listener = new PurgeHttpCacheListener ($ purgerProphecy ->reveal (), $ iriConverterProphecy ->reveal (), $ resourceClassResolverProphecy ->reveal (), $ propertyAccessorProphecy ->reveal ());
106
103
$ listener ->onFlush ($ eventArgs );
107
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 ();
108
108
}
109
109
110
110
public function testPreUpdate (): void
@@ -122,14 +122,13 @@ public function testPreUpdate(): void
122
122
$ purgerProphecy ->purge (['/dummies ' , '/dummies/1 ' , '/related_dummies/old ' , '/related_dummies/new ' ])->shouldBeCalled ();
123
123
124
124
$ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
125
- $ iriConverterProphecy ->getIriFromResource (Dummy::class, UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' )->shouldBeCalled ();
125
+ $ iriConverterProphecy ->getIriFromResource (Argument:: type ( Dummy::class) , UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willReturn ('/dummies ' )->shouldBeCalled ();
126
126
$ iriConverterProphecy ->getIriFromResource ($ dummy )->willReturn ('/dummies/1 ' )->shouldBeCalled ();
127
127
$ iriConverterProphecy ->getIriFromResource ($ oldRelatedDummy )->willReturn ('/related_dummies/old ' )->shouldBeCalled ();
128
128
$ iriConverterProphecy ->getIriFromResource ($ newRelatedDummy )->willReturn ('/related_dummies/new ' )->shouldBeCalled ();
129
129
130
130
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
131
131
$ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true )->shouldBeCalled ();
132
- $ resourceClassResolverProphecy ->getResourceClass (Argument::type (Dummy::class))->willReturn (Dummy::class)->shouldBeCalled ();
133
132
134
133
$ emProphecy = $ this ->prophesize (EntityManagerInterface::class);
135
134
@@ -154,11 +153,11 @@ public function testNothingToPurge(): void
154
153
$ purgerProphecy ->purge ([])->shouldNotBeCalled ();
155
154
156
155
$ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
157
- $ iriConverterProphecy ->getIriFromResource (DummyNoGetOperation::class, UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willThrow (new InvalidArgumentException ())->shouldBeCalled ();
156
+ $ iriConverterProphecy ->getIriFromResource (Argument:: type ( DummyNoGetOperation::class) , UrlGeneratorInterface::ABS_PATH , new GetCollection ())->willThrow (new InvalidArgumentException ())->shouldBeCalled ();
158
157
$ iriConverterProphecy ->getIriFromResource ($ dummyNoGetOperation )->shouldNotBeCalled ();
159
158
160
159
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
161
- $ resourceClassResolverProphecy ->getResourceClass (Argument::type (DummyNoGetOperation::class))->willReturn (DummyNoGetOperation::class)->shouldBeCalled ();
160
+ $ resourceClassResolverProphecy ->getResourceClass (Argument::type (DummyNoGetOperation::class))->willReturn (DummyNoGetOperation::class)->shouldNotBeCalled ();
162
161
163
162
$ emProphecy = $ this ->prophesize (EntityManagerInterface::class);
164
163
@@ -176,18 +175,20 @@ public function testNothingToPurge(): void
176
175
public function testNotAResourceClass (): void
177
176
{
178
177
$ containNonResource = new ContainNonResource ();
179
- $ nonResource = new NotAResource ('foo ' , 'bar ' );
178
+ $ nonResource1 = new NotAResource ('foo ' , 'bar ' );
179
+ $ nonResource2 = new NotAResource ('baz ' , 'qux ' );
180
+ $ collectionOfNotAResource = [$ nonResource1 , $ nonResource2 ];
180
181
181
182
$ purgerProphecy = $ this ->prophesize (PurgerInterface::class);
182
- $ purgerProphecy ->purge ([])->shouldNotBeCalled ();
183
+ $ purgerProphecy ->purge ([' /dummies ' ])->shouldBeCalled ();
183
184
184
185
$ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
185
- $ iriConverterProphecy ->getIriFromResource (ContainNonResource::class, UrlGeneratorInterface::ABS_PATH , Argument::any ())->willReturn ('/dummies/1 ' );
186
- $ iriConverterProphecy ->getIriFromResource ($ nonResource )->shouldNotBeCalled ();
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 ();
187
189
188
190
$ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
189
- $ resourceClassResolverProphecy ->getResourceClass (Argument::type (ContainNonResource::class))->willReturn (ContainNonResource::class)->shouldBeCalled ();
190
- $ resourceClassResolverProphecy ->isResourceClass (NotAResource::class)->willReturn (false )->shouldBeCalled ();
191
+ $ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true )->shouldBeCalled ();
191
192
192
193
$ uowProphecy = $ this ->prophesize (UnitOfWork::class);
193
194
$ uowProphecy ->getScheduledEntityInsertions ()->willReturn ([$ containNonResource ])->shouldBeCalled ();
@@ -208,11 +209,59 @@ public function testNotAResourceClass(): void
208
209
209
210
$ propertyAccessorProphecy = $ this ->prophesize (PropertyAccessorInterface::class);
210
211
$ propertyAccessorProphecy ->isReadable (Argument::type (ContainNonResource::class), 'notAResource ' )->willReturn (true );
211
- $ propertyAccessorProphecy ->isReadable (Argument::type (ContainNonResource::class), 'collectionOfNotAResource ' )->shouldNotBeCalled ( );
212
- $ propertyAccessorProphecy ->getValue (Argument::type (ContainNonResource::class), 'notAResource ' )->shouldBeCalled ()->willReturn ($ nonResource );
213
- $ 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 );
214
215
215
216
$ listener = new PurgeHttpCacheListener ($ purgerProphecy ->reveal (), $ iriConverterProphecy ->reveal (), $ resourceClassResolverProphecy ->reveal (), $ propertyAccessorProphecy ->reveal ());
216
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 ();
217
266
}
218
267
}
0 commit comments