@@ -124,7 +124,33 @@ public function testExecuteWithDryRunDoesNothing(): void
124124
125125 $ callable = fn (User $ user ) => $ user ->getUsernameCanonical ();
126126 $ this ->assertEqualsCanonicalizing (['john ' , 'alice ' ], array_map ($ callable , $ package1 ->getMaintainers ()->toArray ()));
127- $ this ->assertEqualsCanonicalizing (['john ' , 'bob ' ], array_map ($ callable , $ package2 ->getMaintainers ()->toArray ()));
127+ }
128+
129+ public function testExecuteIgnoresIdenticalMaintainers (): void
130+ {
131+ $ this ->commandTester ->execute ([
132+ 'vendorOrPackage ' => 'vendor1 ' ,
133+ 'maintainers ' => ['alice ' , 'john ' ],
134+ ]);
135+
136+ $ this ->commandTester ->assertCommandIsSuccessful ();
137+
138+ $ em = self ::getEM ();
139+ $ em ->clear ();
140+
141+ $ package1 = $ em ->find (Package::class, $ this ->package1 ->getId ());
142+ $ package2 = $ em ->find (Package::class, $ this ->package2 ->getId ());
143+
144+ $ this ->assertNotNull ($ package1 );
145+ $ this ->assertNotNull ($ package2 );
146+
147+ $ callable = fn (User $ user ) => $ user ->getUsernameCanonical ();
148+ $ this ->assertEqualsCanonicalizing (['alice ' , 'john ' ], array_map ($ callable , $ package1 ->getMaintainers ()->toArray ()));
149+ $ this ->assertEqualsCanonicalizing (['alice ' , 'john ' ], array_map ($ callable , $ package2 ->getMaintainers ()->toArray ()));
150+
151+ $ record = $ this ->retrieveAuditRecordForPackage ($ package1 );
152+ $ this ->assertNull ($ record , 'No audit log should be created if package maintainers are identical ' );
153+ $ this ->assertAuditLogWasCreated ($ package2 , ['john ' , 'bob ' ], ['alice ' , 'john ' ]);
128154 }
129155
130156 public function testExecuteFailsWithUnknownMaintainers (): void
@@ -159,12 +185,7 @@ public function testExecuteFailsIfNoVendorPackagesFound(): void
159185 */
160186 private function assertAuditLogWasCreated (Package $ package , array $ oldMaintainers , array $ newMaintainers ): void
161187 {
162- $ record = $ this ->getEM ()->getRepository (AuditRecord::class)->findOneBy ([
163- 'type ' => AuditRecordType::PackageTransferred->value ,
164- 'packageId ' => $ package ->getId (),
165- 'actorId ' => null ,
166- ]);
167-
188+ $ record = $ this ->retrieveAuditRecordForPackage ($ package );
168189 $ this ->assertNotNull ($ record );
169190 $ this ->assertSame ('admin ' , $ record ->attributes ['actor ' ]);
170191 $ this ->assertSame ($ package ->getId (), $ record ->packageId );
@@ -173,4 +194,13 @@ private function assertAuditLogWasCreated(Package $package, array $oldMaintainer
173194 $ this ->assertEqualsCanonicalizing ($ oldMaintainers , array_map ($ callable , $ record ->attributes ['previous_maintainers ' ]));
174195 $ this ->assertEqualsCanonicalizing ($ newMaintainers , array_map ($ callable , $ record ->attributes ['current_maintainers ' ]));
175196 }
197+
198+ private function retrieveAuditRecordForPackage (Package $ package ): ?AuditRecord
199+ {
200+ return $ this ->getEM ()->getRepository (AuditRecord::class)->findOneBy ([
201+ 'type ' => AuditRecordType::PackageTransferred->value ,
202+ 'packageId ' => $ package ->getId (),
203+ 'actorId ' => null ,
204+ ]);
205+ }
176206}
0 commit comments