Skip to content

Commit

Permalink
Merge branch '11.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 10, 2025
2 parents 85a134c + e9f8129 commit f9aaf98
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PHPUnit\Event\Test\MarkedIncomplete;
use PHPUnit\Event\Test\PreparationStarted;
use PHPUnit\Event\Test\Prepared;
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
use PHPUnit\Event\Test\Skipped;
use PHPUnit\Event\TestSuite\Started;
use PHPUnit\Event\UnknownSubscriberTypeException;
Expand Down Expand Up @@ -194,6 +195,16 @@ public function testPrepared(): void
$this->prepared = true;
}

public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void
{
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($event->output()),
);

$this->currentTestCase->appendChild($systemOut);
}

/**
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -288,6 +299,7 @@ private function registerSubscribers(Facade $facade): void
new TestPreparationStartedSubscriber($this),
new TestPreparationFailedSubscriber($this),
new TestPreparedSubscriber($this),
new TestPrintedUnexpectedOutputSubscriber($this),
new TestFinishedSubscriber($this),
new TestErroredSubscriber($this),
new TestFailedSubscriber($this),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Logging\JUnit;

use PHPUnit\Event\Test\PrintedUnexpectedOutput;
use PHPUnit\Event\Test\PrintedUnexpectedOutputSubscriber;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final readonly class TestPrintedUnexpectedOutputSubscriber extends Subscriber implements PrintedUnexpectedOutputSubscriber
{
public function notify(PrintedUnexpectedOutput $event): void
{
$this->logger()->testPrintedUnexpectedOutput($event);
}
}
23 changes: 23 additions & 0 deletions tests/end-to-end/regression/6098.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6098
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-junit';
$_SERVER['argv'][] = 'php://stdout';
$_SERVER['argv'][] = __DIR__ . '/6098/Issue6098Test.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="PHPUnit\TestFixture\Issue6098\Issue6098Test" file="%sIssue6098Test.php" tests="1" assertions="1" errors="0" failures="0" skipped="0" time="%f">
<testcase name="testOne" file="%sIssue6098Test.php" line="16" class="PHPUnit\TestFixture\Issue6098\Issue6098Test" classname="PHPUnit.TestFixture.Issue6098.Issue6098Test" assertions="1" time="%f">
<system-out>output</system-out>
</testcase>
</testsuite>
</testsuites>
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/6098/Issue6098Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue6098;

use PHPUnit\Framework\TestCase;

final class Issue6098Test extends TestCase
{
public function testOne(): void
{
print 'output';

$this->assertTrue(true);
}
}

0 comments on commit f9aaf98

Please sign in to comment.