Skip to content

Commit fd57d97

Browse files
Closes #5445
1 parent 15a89f1 commit fd57d97

8 files changed

+127
-31
lines changed

ChangeLog-10.2.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes of the PHPUnit 10.2 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [10.2.6] - 2023-MM-DD
6+
7+
* [#5445](https://github.com/sebastianbergmann/phpunit/issues/5445): Decouple printing of unexpected output from progress printer
8+
59
## [10.2.5] - 2023-07-14
610

711
### Changed
@@ -56,6 +60,7 @@ All notable changes of the PHPUnit 10.2 release series are documented in this fi
5660
* [#5366](https://github.com/sebastianbergmann/phpunit/issues/5366): `PHPUnit\Event\TestSuite\Loaded` event has incomplete `PHPUnit\Event\TestSuite\TestSuite` value object
5761
* Always use `X.Y.Z` version number (and not just `X.Y`) of PHPUnit's version when checking whether a PHAR-distributed extension is compatible
5862

63+
[10.2.6]: https://github.com/sebastianbergmann/phpunit/compare/10.2.5...10.2
5964
[10.2.5]: https://github.com/sebastianbergmann/phpunit/compare/10.2.4...10.2.5
6065
[10.2.4]: https://github.com/sebastianbergmann/phpunit/compare/10.2.3...10.2.4
6166
[10.2.3]: https://github.com/sebastianbergmann/phpunit/compare/10.2.2...10.2.3

src/TextUI/Output/Default/ProgressPrinter/ProgressPrinter.php

-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use PHPUnit\Event\Test\PhpDeprecationTriggered;
2424
use PHPUnit\Event\Test\PhpNoticeTriggered;
2525
use PHPUnit\Event\Test\PhpWarningTriggered;
26-
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
2726
use PHPUnit\Event\Test\WarningTriggered;
2827
use PHPUnit\Event\TestRunner\ExecutionStarted;
2928
use PHPUnit\Event\UnknownSubscriberTypeException;
@@ -229,11 +228,6 @@ public function testErrored(Errored $event): void
229228
}
230229
}
231230

232-
public function testPrintedOutput(PrintedUnexpectedOutput $event): void
233-
{
234-
$this->printer->print($event->output());
235-
}
236-
237231
public function testFinished(): void
238232
{
239233
if ($this->status === null) {
@@ -284,7 +278,6 @@ private function registerSubscribers(Facade $facade): void
284278
new TestTriggeredPhpunitWarningSubscriber($this),
285279
new TestTriggeredPhpWarningSubscriber($this),
286280
new TestTriggeredWarningSubscriber($this),
287-
new TestPrintedUnexpectedOutputSubscriber($this),
288281
);
289282
}
290283

src/TextUI/Output/Default/ProgressPrinter/Subscriber/TestPrintedUnexpectedOutputSubscriber.php

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\TextUI\Output\Default;
11+
12+
use PHPUnit\Event\EventFacadeIsSealedException;
13+
use PHPUnit\Event\Facade;
14+
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
15+
use PHPUnit\Event\Test\PrintedUnexpectedOutputSubscriber;
16+
use PHPUnit\Event\UnknownSubscriberTypeException;
17+
use PHPUnit\TextUI\Output\Printer;
18+
19+
final class UnexpectedOutputPrinter implements PrintedUnexpectedOutputSubscriber
20+
{
21+
private readonly Printer $printer;
22+
23+
/**
24+
* @throws EventFacadeIsSealedException
25+
* @throws UnknownSubscriberTypeException
26+
*/
27+
public function __construct(Printer $printer, Facade $facade)
28+
{
29+
$this->printer = $printer;
30+
31+
$facade->registerSubscriber($this);
32+
}
33+
34+
public function notify(PrintedUnexpectedOutput $event): void
35+
{
36+
$this->printer->print($event->output());
37+
}
38+
}

src/TextUI/Output/Facade.php

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPUnit\TextUI\InvalidSocketException;
2222
use PHPUnit\TextUI\Output\Default\ProgressPrinter\ProgressPrinter as DefaultProgressPrinter;
2323
use PHPUnit\TextUI\Output\Default\ResultPrinter as DefaultResultPrinter;
24+
use PHPUnit\TextUI\Output\Default\UnexpectedOutputPrinter;
2425
use PHPUnit\TextUI\Output\TestDox\ResultPrinter as TestDoxResultPrinter;
2526
use SebastianBergmann\Timer\Duration;
2627
use SebastianBergmann\Timer\ResourceUsageFormatter;
@@ -46,6 +47,8 @@ public static function init(Configuration $configuration, bool $extensionReplace
4647

4748
assert(self::$printer !== null);
4849

50+
self::createUnexpectedOutputPrinter();
51+
4952
if (!$extensionReplacesProgressOutput) {
5053
self::createProgressPrinter($configuration);
5154
}
@@ -251,4 +254,15 @@ private static function createSummaryPrinter(Configuration $configuration): void
251254
$configuration->colors(),
252255
);
253256
}
257+
258+
/**
259+
* @throws EventFacadeIsSealedException
260+
* @throws UnknownSubscriberTypeException
261+
*/
262+
private static function createUnexpectedOutputPrinter(): void
263+
{
264+
assert(self::$printer !== null);
265+
266+
new UnexpectedOutputPrinter(self::$printer, EventFacade::instance());
267+
}
254268
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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;
11+
12+
use function var_dump;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class UnexpectedOutputTest extends TestCase
16+
{
17+
public function testSomething(): void
18+
{
19+
var_dump(['foo' => 'bar']);
20+
21+
$this->assertSame('something', 'something');
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
phpunit ../../_files/UnexpectedOutputTest.php
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/../_files/UnexpectedOutputTest.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
11+
--EXPECTF--
12+
PHPUnit %s by Sebastian Bergmann and contributors.
13+
14+
Runtime: %s
15+
16+
array(1) {
17+
["foo"]=>
18+
string(3) "bar"
19+
}
20+
. 1 / 1 (100%)
21+
22+
Time: %s, Memory: %s
23+
24+
OK (1 test, 1 assertion)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
phpunit ../../_files/UnexpectedOutputTest.php
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--no-progress';
8+
$_SERVER['argv'][] = __DIR__ . '/../_files/UnexpectedOutputTest.php';
9+
10+
require_once __DIR__ . '/../../bootstrap.php';
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
array(1) {
18+
["foo"]=>
19+
string(3) "bar"
20+
}
21+
Time: %s, Memory: %s
22+
23+
OK (1 test, 1 assertion)

0 commit comments

Comments
 (0)