1010 */
1111
1212namespace {
13+
1314 if (!class_exists ('PHPUnit_Util_String ' )) {
1415
1516 /**
@@ -99,6 +100,11 @@ class JSON extends \PHPUnit\Util\Printer implements \PHPUnit\Framework\TestListe
99100 */
100101 protected $ currentTestPass = true ;
101102
103+ /**
104+ * @var array
105+ */
106+ protected $ logEvents = [];
107+
102108 /**
103109 * An error occurred.
104110 *
@@ -227,9 +233,9 @@ public function addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $ti
227233 public function startTestSuite (\PHPUnit \Framework \TestSuite $ suite )
228234 {
229235 $ this ->currentTestSuiteName = $ suite ->getName ();
230- $ this ->currentTestName = '' ;
236+ $ this ->currentTestName = '' ;
231237
232- $ this ->write (
238+ $ this ->addLogEvent (
233239 [
234240 'event ' => 'suiteStart ' ,
235241 'suite ' => $ this ->currentTestSuiteName ,
@@ -246,7 +252,9 @@ public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
246252 public function endTestSuite (\PHPUnit \Framework \TestSuite $ suite )
247253 {
248254 $ this ->currentTestSuiteName = '' ;
249- $ this ->currentTestName = '' ;
255+ $ this ->currentTestName = '' ;
256+
257+ $ this ->writeAll ($ this ->logEvents );
250258 }
251259
252260 /**
@@ -259,7 +267,7 @@ public function startTest(\PHPUnit\Framework\Test $test)
259267 $ this ->currentTestName = \PHPUnit \Util \Test::describe ($ test );
260268 $ this ->currentTestPass = true ;
261269
262- $ this ->write (
270+ $ this ->addLogEvent (
263271 [
264272 'event ' => 'testStart ' ,
265273 'suite ' => $ this ->currentTestSuiteName ,
@@ -295,7 +303,7 @@ protected function writeCase($status, $time, array $trace = [], $message = '', $
295303 if ($ test !== null && method_exists ($ test , 'hasOutput ' ) && $ test ->hasOutput ()) {
296304 $ output = $ test ->getActualOutput ();
297305 }
298- $ this ->write (
306+ $ this ->addLogEvent (
299307 [
300308 'event ' => 'test ' ,
301309 'suite ' => $ this ->currentTestSuiteName ,
@@ -310,9 +318,19 @@ protected function writeCase($status, $time, array $trace = [], $message = '', $
310318 }
311319
312320 /**
313- * @param string $buffer
321+ * @param array $event_data
322+ */
323+ protected function addLogEvent ($ event_data = [])
324+ {
325+ if (count ($ event_data )) {
326+ array_push ($ this ->logEvents , $ event_data );
327+ }
328+ }
329+
330+ /**
331+ * @param array $buffer
314332 */
315- public function write ($ buffer )
333+ public function writeAll ($ buffer )
316334 {
317335 array_walk_recursive (
318336 $ buffer , function (&$ input ) {
0 commit comments