@@ -24,44 +24,37 @@ class CodewarsResultPrinter extends DefaultResultPrinter
2424 * @var TestSuite
2525 */
2626 private $ wrapperSuite = null ;
27- /**
28- * @var bool
29- */
30- protected $ lastTestFailed = false ;
31-
27+ // Temporarily store failure messages so that the outputs can be written before them.
28+ private $ failures = array ();
3229
3330 /**
3431 * An error occurred.
3532 */
3633 public function addError (Test $ test , \Throwable $ t , float $ time ): void
3734 {
38- $ this ->lastTestFailed = true ;
39- $ this ->write (sprintf ("\n<ERROR::>%s \n" , self ::getMessage ($ t )));
40- $ this ->write (sprintf ("\n<LOG::-Details>%s \n" , self ::escapeLF (self ::getDetails ($ t ))));
35+ $ this ->failures [] = sprintf ("\n<ERROR::>%s \n" , self ::getMessage ($ t ));
36+ $ this ->failures [] = sprintf ("\n<LOG::-Stacktrace>%s \n" , self ::escapeLF (self ::getDetails ($ t )));
4137 }
4238
4339 /**
4440 * A warning occurred.
4541 */
4642 public function addWarning (Test $ test , Warning $ e , float $ time ): void
4743 {
48- $ this ->lastTestFailed = true ;
49- $ this ->write (sprintf ("\n<ERROR::>%s \n" , self ::getMessage ($ e )));
50- $ this ->write (sprintf ("\n<LOG::-Details>%s \n" , self ::escapeLF (self ::getDetails ($ e ))));
44+ $ this ->failures [] = sprintf ("\n<ERROR::>%s \n" , self ::getMessage ($ e ));
45+ $ this ->failures [] = sprintf ("\n<LOG::-Stacktrace>%s \n" , self ::escapeLF (self ::getDetails ($ e )));
5146 }
5247
5348 /**
5449 * A failure occurred.
5550 */
5651 public function addFailure (Test $ test , AssertionFailedError $ e , float $ time ): void
5752 {
58- $ this ->lastTestFailed = true ;
5953 $ msg = self ::getMessage ($ e );
6054 if ($ e instanceof ExpectationFailedException) {
6155 $ msg .= self ::getAssertionDetails ($ e );
6256 }
63- $ this ->write (sprintf ("\n<FAILED::>%s \n" , self ::escapeLF ($ msg )));
64- $ this ->write (sprintf ("\n<LOG::-Details>%s \n" , self ::escapeLF (self ::getDetails ($ e ))));
57+ $ this ->failures [] = sprintf ("\n<FAILED::>%s \n" , self ::escapeLF ($ msg ));
6558 }
6659
6760 /**
@@ -130,16 +123,24 @@ public function endTestSuite(TestSuite $suite): void
130123 public function startTest (Test $ test ): void
131124 {
132125 $ this ->write (sprintf ("\n<IT::>%s \n" , $ test ->getName ()));
126+ $ this ->failures = array ();
133127 }
134128
135129 /**
136130 * A test ended.
137131 */
138132 public function endTest (Test $ test , float $ time ): void
139133 {
140- if (!$ this ->lastTestFailed ) {
134+ if (\method_exists ($ test , 'hasOutput ' ) && \method_exists ($ test , 'getActualOutput ' )) {
135+ if ($ test ->hasOutput ()) {
136+ $ this ->write ($ test ->getActualOutput ());
137+ }
138+ }
139+
140+ if (empty ($ this ->failures )) {
141141 $ this ->write ("\n<PASSED::>Test Passed \n" );
142- $ this ->lastTestFailed = false ;
142+ } else {
143+ $ this ->write (join ("\n" , $ this ->failures ));
143144 }
144145 $ this ->write (sprintf ("\n<COMPLETEDIN::>%.4f \n" , $ time * 1000 ));
145146 }
0 commit comments