1919use App \Entity \User ;
2020use App \Tests \IntegrationTestCase ;
2121use Doctrine \Persistence \ManagerRegistry ;
22+ use PHPUnit \Framework \Attributes \TestWith ;
2223use Symfony \Component \Console \Command \Command ;
2324use Symfony \Component \Console \Tester \CommandTester ;
2425
@@ -48,10 +49,10 @@ protected function setUp(): void
4849 $ this ->commandTester = new CommandTester ($ command );
4950 }
5051
51- public function testExecuteSuccessWithAllMaintainersFound (): void
52+ public function testExecuteSuccessForVendor (): void
5253 {
5354 $ this ->commandTester ->execute ([
54- 'vendor ' => 'vendor1 ' ,
55+ 'vendorOrPackage ' => 'vendor1 ' ,
5556 'maintainers ' => ['bob ' , 'alice ' ],
5657 ]);
5758
@@ -71,17 +72,41 @@ public function testExecuteSuccessWithAllMaintainersFound(): void
7172 $ callable = fn (User $ user ) => $ user ->getUsernameCanonical ();
7273 $ this ->assertEqualsCanonicalizing (['alice ' , 'bob ' ], array_map ($ callable , $ package1 ->getMaintainers ()->toArray ()));
7374 $ this ->assertEqualsCanonicalizing (['alice ' , 'bob ' ], array_map ($ callable , $ package2 ->getMaintainers ()->toArray ()));
74- $ this ->assertEqualsCanonicalizing (['john ' ], array_map ($ callable , $ package3 ->getMaintainers ()->toArray ()), 'vendor1 package maintainers should not be changed ' );
75+ $ this ->assertEqualsCanonicalizing (['john ' ], array_map ($ callable , $ package3 ->getMaintainers ()->toArray ()), 'vendor2 packages should not be changed ' );
7576
7677 $ this ->assertAuditLogWasCreated ($ package1 , ['john ' , 'alice ' ], ['alice ' , 'bob ' ]);
7778 $ this ->assertAuditLogWasCreated ($ package2 , ['john ' , 'bob ' ], ['alice ' , 'bob ' ]);
79+ }
80+
81+ public function testExecuteSuccessForPackage (): void
82+ {
83+ $ this ->commandTester ->execute ([
84+ 'vendorOrPackage ' => 'vendor2/package1 ' ,
85+ 'maintainers ' => ['john ' , 'alice ' ],
86+ ]);
87+
88+ $ this ->commandTester ->assertCommandIsSuccessful ();
89+
90+ $ em = self ::getEM ();
91+ $ em ->clear ();
92+
93+ $ package2 = $ em ->find (Package::class, $ this ->package2 ->getId ());
94+ $ package3 = $ em ->find (Package::class, $ this ->package3 ->getId ());
95+
96+ $ this ->assertNotNull ($ package2 );
97+ $ this ->assertNotNull ($ package3 );
98+
99+ $ callable = fn (User $ user ) => $ user ->getUsernameCanonical ();
100+ $ this ->assertEqualsCanonicalizing (['bob ' , 'john ' ], array_map ($ callable , $ package2 ->getMaintainers ()->toArray ()), 'vendor1 packages should not be changed ' );
101+ $ this ->assertEqualsCanonicalizing (['alice ' , 'john ' ], array_map ($ callable , $ package3 ->getMaintainers ()->toArray ()));
78102
103+ $ this ->assertAuditLogWasCreated ($ package3 , ['john ' ], ['alice ' , 'john ' ]);
79104 }
80105
81106 public function testExecuteWithDryRunDoesNothing (): void
82107 {
83108 $ this ->commandTester ->execute ([
84- 'vendor ' => 'vendor1 ' ,
109+ 'vendorOrPackage ' => 'vendor1 ' ,
85110 'maintainers ' => ['alice ' ],
86111 '--dry-run ' => true ,
87112 ]);
@@ -105,7 +130,7 @@ public function testExecuteWithDryRunDoesNothing(): void
105130 public function testExecuteFailsWithUnknownMaintainers (): void
106131 {
107132 $ this ->commandTester ->execute ([
108- 'vendor ' => 'vendor1 ' ,
133+ 'vendorOrPackage ' => 'vendor1 ' ,
109134 'maintainers ' => ['unknown1 ' , 'alice ' , 'unknown2 ' ],
110135 ]);
111136
@@ -118,14 +143,14 @@ public function testExecuteFailsWithUnknownMaintainers(): void
118143 public function testExecuteFailsIfNoVendorPackagesFound (): void
119144 {
120145 $ this ->commandTester ->execute ([
121- 'vendor ' => 'foobar ' ,
146+ 'vendorOrPackage ' => 'foobar ' ,
122147 'maintainers ' => ['bob ' , 'alice ' ],
123148 ]);
124149
125150 $ this ->assertSame (Command::FAILURE , $ this ->commandTester ->getStatusCode ());
126151
127152 $ output = $ this ->commandTester ->getDisplay ();
128- $ this ->assertStringContainsString ('No packages found for vendor ' , $ output );
153+ $ this ->assertStringContainsString ('No packages found for foobar ' , $ output );
129154 }
130155
131156 /**
0 commit comments