@@ -93,4 +93,98 @@ public function testInvalidUser(): void {
9393
9494 self ::invokePrivate ($ this ->command , 'execute ' , [$ this ->consoleInput , $ this ->consoleOutput ]);
9595 }
96+
97+ public function testAllUsersWithoutExcludeDisabled (): void {
98+ $ enabledUser = $ this ->getMockBuilder (IUser::class)->getMock ();
99+ $ enabledUser ->expects ($ this ->once ())
100+ ->method ('getLastLogin ' )
101+ ->willReturn (time ());
102+ $ enabledUser ->expects ($ this ->once ())
103+ ->method ('getUID ' )
104+ ->willReturn ('enabled_user ' );
105+ $ enabledUser ->expects ($ this ->never ())
106+ ->method ('isEnabled ' );
107+
108+ $ disabledUser = $ this ->getMockBuilder (IUser::class)->getMock ();
109+ $ disabledUser ->expects ($ this ->once ())
110+ ->method ('getLastLogin ' )
111+ ->willReturn (time ());
112+ $ disabledUser ->expects ($ this ->once ())
113+ ->method ('getUID ' )
114+ ->willReturn ('disabled_user ' );
115+ $ disabledUser ->expects ($ this ->never ())
116+ ->method ('isEnabled ' );
117+
118+ $ this ->consoleInput ->expects ($ this ->once ())
119+ ->method ('getArgument ' )
120+ ->with ('uid ' )
121+ ->willReturn (null );
122+
123+ $ this ->consoleInput ->expects ($ this ->exactly (2 ))
124+ ->method ('getOption ' )
125+ ->willReturnMap ([
126+ ['all ' , true ],
127+ ['exclude-disabled ' , false ],
128+ ]);
129+
130+ $ this ->userManager ->expects ($ this ->once ())
131+ ->method ('callForAllUsers ' )
132+ ->willReturnCallback (function ($ callback ) use ($ enabledUser , $ disabledUser ) {
133+ $ callback ($ enabledUser );
134+ $ callback ($ disabledUser );
135+ });
136+
137+ $ this ->consoleOutput ->expects ($ this ->exactly (2 ))
138+ ->method ('writeln ' )
139+ ->with ($ this ->stringContains ("'s last login: " ));
140+
141+ self ::invokePrivate ($ this ->command , 'execute ' , [$ this ->consoleInput , $ this ->consoleOutput ]);
142+ }
143+
144+ public function testAllUsersWithExcludeDisabled (): void {
145+ $ enabledUser = $ this ->getMockBuilder (IUser::class)->getMock ();
146+ $ enabledUser ->expects ($ this ->once ())
147+ ->method ('getLastLogin ' )
148+ ->willReturn (time ());
149+ $ enabledUser ->expects ($ this ->once ())
150+ ->method ('getUID ' )
151+ ->willReturn ('enabled_user ' );
152+ $ enabledUser ->expects ($ this ->once ())
153+ ->method ('isEnabled ' )
154+ ->willReturn (true );
155+
156+ $ disabledUser = $ this ->getMockBuilder (IUser::class)->getMock ();
157+ $ disabledUser ->expects ($ this ->never ())
158+ ->method ('getLastLogin ' );
159+ $ disabledUser ->expects ($ this ->never ())
160+ ->method ('getUID ' );
161+ $ disabledUser ->expects ($ this ->once ())
162+ ->method ('isEnabled ' )
163+ ->willReturn (false );
164+
165+ $ this ->consoleInput ->expects ($ this ->once ())
166+ ->method ('getArgument ' )
167+ ->with ('uid ' )
168+ ->willReturn (null );
169+
170+ $ this ->consoleInput ->expects ($ this ->exactly (2 ))
171+ ->method ('getOption ' )
172+ ->willReturnMap ([
173+ ['all ' , true ],
174+ ['exclude-disabled ' , true ],
175+ ]);
176+
177+ $ this ->userManager ->expects ($ this ->once ())
178+ ->method ('callForAllUsers ' )
179+ ->willReturnCallback (function ($ callback ) use ($ enabledUser , $ disabledUser ) {
180+ $ callback ($ enabledUser );
181+ $ callback ($ disabledUser );
182+ });
183+
184+ $ this ->consoleOutput ->expects ($ this ->once ())
185+ ->method ('writeln ' )
186+ ->with ($ this ->stringContains ("enabled_user's last login: " ));
187+
188+ self ::invokePrivate ($ this ->command , 'execute ' , [$ this ->consoleInput , $ this ->consoleOutput ]);
189+ }
96190}
0 commit comments