Skip to content

Commit d099069

Browse files
Closes #6098
1 parent a7dbfad commit d099069

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

ChangeLog-10.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
1111
### Fixed
1212

1313
* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected
14+
* [#6098](https://github.com/sebastianbergmann/phpunit/issues/6098): No `system-out` element in JUnit XML logfile
1415

1516
## [10.5.40] - 2024-12-21
1617

src/Logging/JUnit/JunitXmlLogger.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use PHPUnit\Event\Test\MarkedIncomplete;
3232
use PHPUnit\Event\Test\PreparationStarted;
3333
use PHPUnit\Event\Test\Prepared;
34+
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
3435
use PHPUnit\Event\Test\Skipped;
3536
use PHPUnit\Event\TestSuite\Started;
3637
use PHPUnit\Event\UnknownSubscriberTypeException;
@@ -200,6 +201,16 @@ public function testPrepared(): void
200201
$this->prepared = true;
201202
}
202203

204+
public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void
205+
{
206+
$systemOut = $this->document->createElement(
207+
'system-out',
208+
Xml::prepareString($event->output()),
209+
);
210+
211+
$this->currentTestCase->appendChild($systemOut);
212+
}
213+
203214
/**
204215
* @throws InvalidArgumentException
205216
*/
@@ -294,6 +305,7 @@ private function registerSubscribers(Facade $facade): void
294305
new TestPreparationStartedSubscriber($this),
295306
new TestPreparationFailedSubscriber($this),
296307
new TestPreparedSubscriber($this),
308+
new TestPrintedUnexpectedOutputSubscriber($this),
297309
new TestFinishedSubscriber($this),
298310
new TestErroredSubscriber($this),
299311
new TestFailedSubscriber($this),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\Logging\JUnit;
11+
12+
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
13+
use PHPUnit\Event\Test\PrintedUnexpectedOutputSubscriber;
14+
15+
/**
16+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
17+
*
18+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final class TestPrintedUnexpectedOutputSubscriber extends Subscriber implements PrintedUnexpectedOutputSubscriber
21+
{
22+
public function notify(PrintedUnexpectedOutput $event): void
23+
{
24+
$this->logger()->testPrintedUnexpectedOutput($event);
25+
}
26+
}

tests/end-to-end/regression/6098.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6098
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--no-output';
8+
$_SERVER['argv'][] = '--log-junit';
9+
$_SERVER['argv'][] = 'php://stdout';
10+
$_SERVER['argv'][] = __DIR__ . '/6098/Issue6098Test.php';
11+
12+
require_once __DIR__ . '/../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
<?xml version="1.0" encoding="UTF-8"?>
17+
<testsuites>
18+
<testsuite name="PHPUnit\TestFixture\Issue6098\Issue6098Test" file="%sIssue6098Test.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="%f">
19+
<testcase name="testOne" file="%sIssue6098Test.php" line="16" class="PHPUnit\TestFixture\Issue6098\Issue6098Test" classname="PHPUnit.TestFixture.Issue6098.Issue6098Test" assertions="1" time="%f">
20+
<system-out>output</system-out>
21+
</testcase>
22+
</testsuite>
23+
</testsuites>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue6098;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class Issue6098Test extends TestCase
15+
{
16+
public function testOne(): void
17+
{
18+
print 'output';
19+
20+
$this->assertTrue(true);
21+
}
22+
}

0 commit comments

Comments
 (0)