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