@@ -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,84 @@ 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+ $ user1 = $ this ->createMock (IUser::class);
120+ $ user2 = $ this ->createMock (IUser::class);
121+ $ this ->userManager ->method ('get ' )
122+ ->willReturnMap ([
123+ ['myUser ' , $ user1 ],
124+ ['myOtherUser ' , $ user2 ],
125+ ]);
126+
127+ $ group ->expects ($ this ->exactly (2 ))
128+ ->method ('removeUser ' )
129+ ->with ($ this ->callback (static fn (IUser $ user ): bool => in_array ($ user , [$ user1 , $ user2 ], true )));
130+
131+ $ this ->output ->expects ($ this ->exactly (2 ))
132+ ->method ('writeln ' )
133+ ->with ($ this ->callback (static fn (string $ message ): bool => in_array ($ message ,
134+ [
135+ '<info>user myUser removed</info> ' ,
136+ '<info>user myOtherUser removed</info> ' ,
137+ ], true )));
138+
139+ $ this ->invokePrivate ($ this ->command , 'execute ' , [$ this ->input , $ this ->output ]);
140+ }
141+
142+ public function testRemoveMultiplePartialSuccess (): void {
143+ $ this ->input ->method ('getArgument ' )
144+ ->willReturnCallback (function ($ arg ) {
145+ if ($ arg === 'group ' ) {
146+ return 'myGroup ' ;
147+ }
148+ if ($ arg === 'user ' ) {
149+ return ['myUser ' , 'myOtherUser ' ];
150+ }
151+ throw new \Exception ();
152+ });
153+
154+ $ group = $ this ->createMock (IGroup::class);
155+ $ this ->groupManager ->method ('get ' )
156+ ->with ('myGroup ' )
157+ ->willReturn ($ group );
158+
159+ $ user = $ this ->createMock (IUser::class);
160+ $ this ->userManager ->method ('get ' )
161+ ->willReturnMap ([
162+ ['myUser ' , $ user ],
163+ ['myOtherUser ' , null ],
164+ ]);
165+
166+ $ group ->expects ($ this ->once ())
167+ ->method ('removeUser ' )
168+ ->with ($ user );
169+
170+ $ this ->output ->expects ($ this ->exactly (3 ))
171+ ->method ('writeln ' )
172+ ->with ($ this ->callback (static fn (string $ message ): bool => in_array ($ message ,
173+ [
174+ '<info>user myUser removed</info> ' ,
175+ '<error>user myOtherUser not found</error> ' ,
176+ '<error>Some users were not found, all others where removed from the group.</error> ' ,
177+ ], true )));
178+
179+ $ this ->invokePrivate ($ this ->command , 'execute ' , [$ this ->input , $ this ->output ]);
180+ }
101181}
0 commit comments