@@ -53,7 +53,6 @@ public function testAuditCollectionNonManyToManyReturnsCollectionAsSubject(): vo
5353 [$ subject , $ payload , $ eventType ] = $ method ->invoke (
5454 $ listener ,
5555 $ collection ,
56- new \stdClass (),
5756 IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_UPDATE
5857 );
5958
@@ -155,7 +154,62 @@ public function testAuditCollectionDeleteInitializedWithoutDiffUsesJoinTableQuer
155154 [$ subject , $ payload , $ eventType ] = $ method ->invoke (
156155 $ listener ,
157156 $ collection ,
158- new \stdClass (),
157+ IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_DELETE
158+ );
159+
160+ $ this ->assertSame ($ owner , $ subject );
161+ $ this ->assertSame ([10 , 11 ], $ payload ['deleted_ids ' ]);
162+ $ this ->assertSame (IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_DELETE , $ eventType );
163+ }
164+
165+ public function testAuditCollectionDeleteUninitializedUsesJoinTableQuery (): void
166+ {
167+ $ listener = new AuditEventListener ();
168+ $ owner = new \stdClass ();
169+
170+ $ mapping = ManyToManyOwningSideMapping::fromMappingArrayAndNamingStrategy ([
171+ 'fieldName ' => 'tags ' ,
172+ 'sourceEntity ' => \stdClass::class,
173+ 'targetEntity ' => \stdClass::class,
174+ 'isOwningSide ' => true ,
175+ 'joinTable ' => [
176+ 'name ' => 'owner_tags ' ,
177+ 'joinColumns ' => [['name ' => 'owner_id ' , 'referencedColumnName ' => 'id ' ]],
178+ 'inverseJoinColumns ' => [['name ' => 'tag_id ' , 'referencedColumnName ' => 'id ' ]],
179+ ],
180+ ], new DefaultNamingStrategy ());
181+
182+ $ em = $ this ->createMock (EntityManagerInterface::class);
183+ $ meta = new ClassMetadata (\stdClass::class);
184+ $ collection = new PersistentCollection ($ em , $ meta , new ArrayCollection ());
185+ $ collection ->setOwner ($ owner , $ mapping );
186+ $ collection ->setInitialized (false );
187+
188+ $ this ->assertFalse ($ collection ->isInitialized ());
189+
190+ $ ownerMeta = $ this ->getMockBuilder (ClassMetadata::class)
191+ ->disableOriginalConstructor ()
192+ ->getMock ();
193+ $ ownerMeta ->method ('getIdentifierValues ' )->with ($ owner )->willReturn (['id ' => 123 ]);
194+
195+ $ conn = $ this ->getMockBuilder (Connection::class)
196+ ->disableOriginalConstructor ()
197+ ->getMock ();
198+ $ conn ->method ('fetchFirstColumn ' )->willReturn (['10 ' , '11 ' ]);
199+
200+ $ em ->method ('getConnection ' )->willReturn ($ conn );
201+ $ em ->method ('getClassMetadata ' )->with (get_class ($ owner ))->willReturn ($ ownerMeta );
202+
203+ $ emProp = new \ReflectionProperty (AuditEventListener::class, 'em ' );
204+ $ emProp ->setAccessible (true );
205+ $ emProp ->setValue ($ listener , $ em );
206+
207+ $ method = new \ReflectionMethod (AuditEventListener::class, 'auditCollection ' );
208+ $ method ->setAccessible (true );
209+
210+ [$ subject , $ payload , $ eventType ] = $ method ->invoke (
211+ $ listener ,
212+ $ collection ,
159213 IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_DELETE
160214 );
161215
0 commit comments