@@ -24,44 +24,37 @@ class CodewarsResultPrinter extends DefaultResultPrinter
24
24
* @var TestSuite
25
25
*/
26
26
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 ();
32
29
33
30
/**
34
31
* An error occurred.
35
32
*/
36
33
public function addError (Test $ test , \Throwable $ t , float $ time ): void
37
34
{
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 )));
41
37
}
42
38
43
39
/**
44
40
* A warning occurred.
45
41
*/
46
42
public function addWarning (Test $ test , Warning $ e , float $ time ): void
47
43
{
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 )));
51
46
}
52
47
53
48
/**
54
49
* A failure occurred.
55
50
*/
56
51
public function addFailure (Test $ test , AssertionFailedError $ e , float $ time ): void
57
52
{
58
- $ this ->lastTestFailed = true ;
59
53
$ msg = self ::getMessage ($ e );
60
54
if ($ e instanceof ExpectationFailedException) {
61
55
$ msg .= self ::getAssertionDetails ($ e );
62
56
}
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 ));
65
58
}
66
59
67
60
/**
@@ -130,16 +123,24 @@ public function endTestSuite(TestSuite $suite): void
130
123
public function startTest (Test $ test ): void
131
124
{
132
125
$ this ->write (sprintf ("\n<IT::>%s \n" , $ test ->getName ()));
126
+ $ this ->failures = array ();
133
127
}
134
128
135
129
/**
136
130
* A test ended.
137
131
*/
138
132
public function endTest (Test $ test , float $ time ): void
139
133
{
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 )) {
141
141
$ this ->write ("\n<PASSED::>Test Passed \n" );
142
- $ this ->lastTestFailed = false ;
142
+ } else {
143
+ $ this ->write (join ("\n" , $ this ->failures ));
143
144
}
144
145
$ this ->write (sprintf ("\n<COMPLETEDIN::>%.4f \n" , $ time * 1000 ));
145
146
}
0 commit comments