@@ -77,12 +77,12 @@ public function testNoUser(): void {
7777
7878 $ this ->output ->expects ($ this ->once ())
7979 ->method ('writeln ' )
80- ->with ('<error>user not found</error> ' );
80+ ->with ('<error>user myUser not found</error> ' );
8181
8282 $ this ->invokePrivate ($ this ->command , 'execute ' , [$ this ->input , $ this ->output ]);
8383 }
8484
85- public function testAdd (): void {
85+ public function testRemove (): void {
8686 $ group = $ this ->createMock (IGroup::class);
8787 $ this ->groupManager ->method ('get ' )
8888 ->with ('myGroup ' )
@@ -99,4 +99,84 @@ public function testAdd(): void {
9999
100100 $ this ->invokePrivate ($ this ->command , 'execute ' , [$ this ->input , $ this ->output ]);
101101 }
102+
103+ public function testRemoveMultiple (): void {
104+ $ this ->input ->method ('getArgument ' )
105+ ->willReturnCallback (function ($ arg ) {
106+ if ($ arg === 'group ' ) {
107+ return 'myGroup ' ;
108+ }
109+ if ($ arg === 'user ' ) {
110+ return ['myUser ' , 'myOtherUser ' ];
111+ }
112+ throw new \Exception ();
113+ });
114+
115+ $ group = $ this ->createMock (IGroup::class);
116+ $ this ->groupManager ->method ('get ' )
117+ ->with ('myGroup ' )
118+ ->willReturn ($ group );
119+
120+ $ user1 = $ this ->createMock (IUser::class);
121+ $ user2 = $ this ->createMock (IUser::class);
122+ $ this ->userManager ->method ('get ' )
123+ ->willReturnMap ([
124+ ['myUser ' , $ user1 ],
125+ ['myOtherUser ' , $ user2 ],
126+ ]);
127+
128+ $ group ->expects ($ this ->exactly (2 ))
129+ ->method ('removeUser ' )
130+ ->with ($ this ->callback (static fn (IUser $ user ): bool => in_array ($ user , [$ user1 , $ user2 ], true )));
131+
132+ $ this ->output ->expects ($ this ->exactly (2 ))
133+ ->method ('writeln ' )
134+ ->with ($ this ->callback (static fn (string $ message ): bool => in_array ($ message ,
135+ [
136+ '<info>user myUser removed</info> ' ,
137+ '<info>user myOtherUser removed</info> ' ,
138+ ], true )));
139+
140+ $ this ->invokePrivate ($ this ->command , 'execute ' , [$ this ->input , $ this ->output ]);
141+ }
142+
143+ public function testRemoveMultiplePartialSuccess (): void {
144+ $ this ->input ->method ('getArgument ' )
145+ ->willReturnCallback (function ($ arg ) {
146+ if ($ arg === 'group ' ) {
147+ return 'myGroup ' ;
148+ }
149+ if ($ arg === 'user ' ) {
150+ return ['myUser ' , 'myOtherUser ' ];
151+ }
152+ throw new \Exception ();
153+ });
154+
155+ $ group = $ this ->createMock (IGroup::class);
156+ $ this ->groupManager ->method ('get ' )
157+ ->with ('myGroup ' )
158+ ->willReturn ($ group );
159+
160+ $ user = $ this ->createMock (IUser::class);
161+ $ this ->userManager ->method ('get ' )
162+ ->willReturnMap ([
163+ ['myUser ' , $ user ],
164+ ['myOtherUser ' , null ],
165+ ]);
166+
167+ $ group ->expects ($ this ->once ())
168+ ->method ('removeUser ' )
169+ ->with ($ user );
170+
171+ $ this ->output ->expects ($ this ->exactly (3 ))
172+ ->method ('writeln ' )
173+ ->with ($ this ->callback (static fn (string $ message ): bool => in_array ($ message ,
174+ [
175+ '<info>user myUser removed</info> ' ,
176+ '<error>user myOtherUser not found</error> ' ,
177+ '<error>Some users were not found, all others where removed from the group.</error> ' ,
178+ ], true )));
179+
180+ $ this ->invokePrivate ($ this ->command , 'execute ' , [$ this ->input , $ this ->output ]);
181+ }
102182}
0 commit comments