10
10
*/
11
11
12
12
namespace {
13
+
13
14
if (!class_exists ('PHPUnit_Util_String ' )) {
14
15
15
16
/**
@@ -99,6 +100,11 @@ class JSON extends \PHPUnit\Util\Printer implements \PHPUnit\Framework\TestListe
99
100
*/
100
101
protected $ currentTestPass = true ;
101
102
103
+ /**
104
+ * @var array
105
+ */
106
+ protected $ logEvents = [];
107
+
102
108
/**
103
109
* An error occurred.
104
110
*
@@ -227,9 +233,9 @@ public function addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $ti
227
233
public function startTestSuite (\PHPUnit \Framework \TestSuite $ suite )
228
234
{
229
235
$ this ->currentTestSuiteName = $ suite ->getName ();
230
- $ this ->currentTestName = '' ;
236
+ $ this ->currentTestName = '' ;
231
237
232
- $ this ->write (
238
+ $ this ->addLogEvent (
233
239
[
234
240
'event ' => 'suiteStart ' ,
235
241
'suite ' => $ this ->currentTestSuiteName ,
@@ -246,7 +252,9 @@ public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
246
252
public function endTestSuite (\PHPUnit \Framework \TestSuite $ suite )
247
253
{
248
254
$ this ->currentTestSuiteName = '' ;
249
- $ this ->currentTestName = '' ;
255
+ $ this ->currentTestName = '' ;
256
+
257
+ $ this ->writeAll ($ this ->logEvents );
250
258
}
251
259
252
260
/**
@@ -259,7 +267,7 @@ public function startTest(\PHPUnit\Framework\Test $test)
259
267
$ this ->currentTestName = \PHPUnit \Util \Test::describe ($ test );
260
268
$ this ->currentTestPass = true ;
261
269
262
- $ this ->write (
270
+ $ this ->addLogEvent (
263
271
[
264
272
'event ' => 'testStart ' ,
265
273
'suite ' => $ this ->currentTestSuiteName ,
@@ -295,7 +303,7 @@ protected function writeCase($status, $time, array $trace = [], $message = '', $
295
303
if ($ test !== null && method_exists ($ test , 'hasOutput ' ) && $ test ->hasOutput ()) {
296
304
$ output = $ test ->getActualOutput ();
297
305
}
298
- $ this ->write (
306
+ $ this ->addLogEvent (
299
307
[
300
308
'event ' => 'test ' ,
301
309
'suite ' => $ this ->currentTestSuiteName ,
@@ -310,9 +318,19 @@ protected function writeCase($status, $time, array $trace = [], $message = '', $
310
318
}
311
319
312
320
/**
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
314
332
*/
315
- public function write ($ buffer )
333
+ public function writeAll ($ buffer )
316
334
{
317
335
array_walk_recursive (
318
336
$ buffer , function (&$ input ) {
0 commit comments