@@ -144,6 +144,102 @@ public function testStartTaskGitlabCI(): void
144144 $ logger ->startTask (new Task ('deploy ' , function () {}));
145145 }
146146
147+ public function testEndTaskVeryVerbosePrintsDuration (): void
148+ {
149+ $ output = $ this ->createMock (OutputInterface::class);
150+ $ output ->method ('isVeryVerbose ' )->willReturn (true );
151+ $ output ->expects ($ this ->once ())
152+ ->method ('writeln ' )
153+ ->with ($ this ->logicalAnd (
154+ $ this ->stringContains ('done ' ),
155+ $ this ->stringContains ('deploy ' ),
156+ $ this ->stringContains ('ms ' ),
157+ ));
158+
159+ $ fileLog = $ this ->createStub (HandlerInterface::class);
160+
161+ $ logger = new Logger ($ output , $ fileLog );
162+ $ logger ->endTask (new Task ('deploy ' , function () {}));
163+ }
164+
165+ public function testEndTaskNonVerboseSkipsOutput (): void
166+ {
167+ $ output = $ this ->createMock (OutputInterface::class);
168+ $ output ->method ('isVeryVerbose ' )->willReturn (false );
169+ $ output ->expects ($ this ->never ())->method ('writeln ' );
170+
171+ $ fileLog = $ this ->createStub (HandlerInterface::class);
172+
173+ $ logger = new Logger ($ output , $ fileLog );
174+ $ logger ->endTask (new Task ('deploy ' , function () {}));
175+ }
176+
177+ public function testEndTaskGithubCIAlwaysPrintsDuration (): void
178+ {
179+ putenv ('GITHUB_WORKFLOW=test ' );
180+
181+ $ output = $ this ->createMock (OutputInterface::class);
182+ $ output ->method ('isVeryVerbose ' )->willReturn (false );
183+ $ writelnArgs = [];
184+ $ output ->expects ($ this ->exactly (2 ))
185+ ->method ('writeln ' )
186+ ->willReturnCallback (function ($ msg ) use (&$ writelnArgs ) {
187+ $ writelnArgs [] = $ msg ;
188+ });
189+
190+ $ fileLog = $ this ->createStub (HandlerInterface::class);
191+
192+ $ logger = new Logger ($ output , $ fileLog );
193+ $ logger ->endTask (new Task ('deploy ' , function () {}));
194+
195+ $ this ->assertStringContainsString ('done ' , $ writelnArgs [0 ]);
196+ $ this ->assertStringContainsString ('deploy ' , $ writelnArgs [0 ]);
197+ $ this ->assertStringContainsString ('ms ' , $ writelnArgs [0 ]);
198+ $ this ->assertEquals ('::endgroup:: ' , $ writelnArgs [1 ]);
199+ }
200+
201+ public function testEndTaskGitlabCIAlwaysPrintsDuration (): void
202+ {
203+ putenv ('GITLAB_CI=true ' );
204+
205+ $ output = $ this ->createMock (OutputInterface::class);
206+ $ output ->method ('isVeryVerbose ' )->willReturn (false );
207+ $ writelnArgs = [];
208+ $ output ->expects ($ this ->exactly (2 ))
209+ ->method ('writeln ' )
210+ ->willReturnCallback (function ($ msg ) use (&$ writelnArgs ) {
211+ $ writelnArgs [] = $ msg ;
212+ });
213+
214+ $ fileLog = $ this ->createStub (HandlerInterface::class);
215+
216+ $ logger = new Logger ($ output , $ fileLog );
217+ $ logger ->endTask (new Task ('deploy ' , function () {}));
218+
219+ $ this ->assertStringContainsString ('done ' , $ writelnArgs [0 ]);
220+ $ this ->assertStringContainsString ('deploy ' , $ writelnArgs [0 ]);
221+ $ this ->assertStringContainsString ('ms ' , $ writelnArgs [0 ]);
222+ $ this ->assertStringContainsString ('section_end: ' , $ writelnArgs [1 ]);
223+ }
224+
225+ public function testEndTaskWritesDurationToFileLog (): void
226+ {
227+ $ output = $ this ->createStub (OutputInterface::class);
228+ $ output ->method ('isVeryVerbose ' )->willReturn (false );
229+
230+ $ fileLog = $ this ->createMock (HandlerInterface::class);
231+ $ fileLog ->expects ($ this ->once ())
232+ ->method ('writeln ' )
233+ ->with ($ this ->logicalAnd (
234+ $ this ->stringContains ('done ' ),
235+ $ this ->stringContains ('deploy ' ),
236+ $ this ->stringContains ('ms ' ),
237+ ));
238+
239+ $ logger = new Logger ($ output , $ fileLog );
240+ $ logger ->endTask (new Task ('deploy ' , function () {}));
241+ }
242+
147243 public function testEndOnHostWritesToFileLog (): void
148244 {
149245 $ output = $ this ->createStub (OutputInterface::class);
0 commit comments