27
27
use PHPUnit \Event \Test \MarkedIncomplete ;
28
28
use PHPUnit \Event \Test \PreparationStarted ;
29
29
use PHPUnit \Event \Test \Prepared ;
30
+ use PHPUnit \Event \Test \PrintedUnexpectedOutput ;
30
31
use PHPUnit \Event \Test \Skipped ;
31
32
use PHPUnit \Event \TestSuite \Started ;
32
33
use PHPUnit \Event \UnknownSubscriberTypeException ;
41
42
use function trim ;
42
43
43
44
/**
45
+ * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
46
+ *
44
47
* @internal This class is not covered by the backward compatibility promise for PHPUnit
45
48
*/
46
49
final class JunitXmlLogger
@@ -59,32 +62,32 @@ final class JunitXmlLogger
59
62
private array $ testSuites = [];
60
63
61
64
/**
62
- * @psalm- var array<int,int>
65
+ * @var array<int,int>
63
66
*/
64
67
private array $ testSuiteTests = [0 ];
65
68
66
69
/**
67
- * @psalm- var array<int,int>
70
+ * @var array<int,int>
68
71
*/
69
72
private array $ testSuiteAssertions = [0 ];
70
73
71
74
/**
72
- * @psalm- var array<int,int>
75
+ * @var array<int,int>
73
76
*/
74
77
private array $ testSuiteErrors = [0 ];
75
78
76
79
/**
77
- * @psalm- var array<int,int>
80
+ * @var array<int,int>
78
81
*/
79
82
private array $ testSuiteFailures = [0 ];
80
83
81
84
/**
82
- * @psalm- var array<int,int>
85
+ * @var array<int,int>
83
86
*/
84
87
private array $ testSuiteSkipped = [0 ];
85
88
86
89
/**
87
- * @psalm- var array<int,int>
90
+ * @var array<int,int>
88
91
*/
89
92
private array $ testSuiteTimes = [0 ];
90
93
@@ -113,7 +116,7 @@ public function __construct(Printer $printer, Facade $facade)
113
116
114
117
public function flush (): void
115
118
{
116
- $ this ->printer ->print ($ this ->document ->saveXML ());
119
+ $ this ->printer ->print ($ this ->document ->saveXML () ?: '' );
117
120
118
121
$ this ->printer ->flush ();
119
122
}
@@ -195,28 +198,34 @@ public function testPreparationStarted(PreparationStarted $event): void
195
198
$ this ->createTestCase ($ event );
196
199
}
197
200
198
- /**
199
- * @throws InvalidArgumentException
200
- */
201
201
public function testPreparationFailed (): void
202
202
{
203
203
$ this ->preparationFailed = true ;
204
204
}
205
205
206
- /**
207
- * @throws InvalidArgumentException
208
- */
209
206
public function testPrepared (): void
210
207
{
211
208
$ this ->prepared = true ;
212
209
}
213
210
211
+ public function testPrintedUnexpectedOutput (PrintedUnexpectedOutput $ event ): void
212
+ {
213
+ assert ($ this ->currentTestCase !== null );
214
+
215
+ $ systemOut = $ this ->document ->createElement (
216
+ 'system-out ' ,
217
+ Xml::prepareString ($ event ->output ()),
218
+ );
219
+
220
+ $ this ->currentTestCase ->appendChild ($ systemOut );
221
+ }
222
+
214
223
/**
215
224
* @throws InvalidArgumentException
216
225
*/
217
226
public function testFinished (Finished $ event ): void
218
227
{
219
- if ($ this ->preparationFailed ) {
228
+ if (! $ this -> prepared || $ this ->preparationFailed ) {
220
229
return ;
221
230
}
222
231
@@ -305,9 +314,11 @@ private function registerSubscribers(Facade $facade): void
305
314
new TestPreparationStartedSubscriber ($ this ),
306
315
new TestPreparationFailedSubscriber ($ this ),
307
316
new TestPreparedSubscriber ($ this ),
317
+ new TestPrintedUnexpectedOutputSubscriber ($ this ),
308
318
new TestFinishedSubscriber ($ this ),
309
319
new TestErroredSubscriber ($ this ),
310
320
new TestFailedSubscriber ($ this ),
321
+ new TestMarkedIncompleteSubscriber ($ this ),
311
322
new TestSkippedSubscriber ($ this ),
312
323
new TestRunnerExecutionFinishedSubscriber ($ this ),
313
324
);
@@ -431,7 +442,7 @@ private function name(Test $test): string
431
442
/**
432
443
* @throws InvalidArgumentException
433
444
*
434
- * @psalm -assert !null $this->currentTestCase
445
+ * @phpstan -assert !null $this->currentTestCase
435
446
*/
436
447
private function createTestCase (Errored |Failed |MarkedIncomplete |PreparationStarted |Prepared |Skipped $ event ): void
437
448
{
0 commit comments