Skip to content

Commit

Permalink
Closes #5445
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 14, 2023
1 parent 15a89f1 commit fd57d97
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 31 deletions.
5 changes: 5 additions & 0 deletions ChangeLog-10.2.md
Expand Up @@ -2,6 +2,10 @@

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

## [10.2.6] - 2023-MM-DD

* [#5445](https://github.com/sebastianbergmann/phpunit/issues/5445): Decouple printing of unexpected output from progress printer

## [10.2.5] - 2023-07-14

### Changed
Expand Down Expand Up @@ -56,6 +60,7 @@ All notable changes of the PHPUnit 10.2 release series are documented in this fi
* [#5366](https://github.com/sebastianbergmann/phpunit/issues/5366): `PHPUnit\Event\TestSuite\Loaded` event has incomplete `PHPUnit\Event\TestSuite\TestSuite` value object
* 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

[10.2.6]: https://github.com/sebastianbergmann/phpunit/compare/10.2.5...10.2
[10.2.5]: https://github.com/sebastianbergmann/phpunit/compare/10.2.4...10.2.5
[10.2.4]: https://github.com/sebastianbergmann/phpunit/compare/10.2.3...10.2.4
[10.2.3]: https://github.com/sebastianbergmann/phpunit/compare/10.2.2...10.2.3
Expand Down
7 changes: 0 additions & 7 deletions src/TextUI/Output/Default/ProgressPrinter/ProgressPrinter.php
Expand Up @@ -23,7 +23,6 @@
use PHPUnit\Event\Test\PhpDeprecationTriggered;
use PHPUnit\Event\Test\PhpNoticeTriggered;
use PHPUnit\Event\Test\PhpWarningTriggered;
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
use PHPUnit\Event\Test\WarningTriggered;
use PHPUnit\Event\TestRunner\ExecutionStarted;
use PHPUnit\Event\UnknownSubscriberTypeException;
Expand Down Expand Up @@ -229,11 +228,6 @@ public function testErrored(Errored $event): void
}
}

public function testPrintedOutput(PrintedUnexpectedOutput $event): void
{
$this->printer->print($event->output());
}

public function testFinished(): void
{
if ($this->status === null) {
Expand Down Expand Up @@ -284,7 +278,6 @@ private function registerSubscribers(Facade $facade): void
new TestTriggeredPhpunitWarningSubscriber($this),
new TestTriggeredPhpWarningSubscriber($this),
new TestTriggeredWarningSubscriber($this),
new TestPrintedUnexpectedOutputSubscriber($this),
);
}

Expand Down

This file was deleted.

38 changes: 38 additions & 0 deletions src/TextUI/Output/Default/UnexpectedOutputPrinter.php
@@ -0,0 +1,38 @@
<?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\TextUI\Output\Default;

use PHPUnit\Event\EventFacadeIsSealedException;
use PHPUnit\Event\Facade;
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
use PHPUnit\Event\Test\PrintedUnexpectedOutputSubscriber;
use PHPUnit\Event\UnknownSubscriberTypeException;
use PHPUnit\TextUI\Output\Printer;

final class UnexpectedOutputPrinter implements PrintedUnexpectedOutputSubscriber
{
private readonly Printer $printer;

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
public function __construct(Printer $printer, Facade $facade)
{
$this->printer = $printer;

$facade->registerSubscriber($this);
}

public function notify(PrintedUnexpectedOutput $event): void
{
$this->printer->print($event->output());
}
}
14 changes: 14 additions & 0 deletions src/TextUI/Output/Facade.php
Expand Up @@ -21,6 +21,7 @@
use PHPUnit\TextUI\InvalidSocketException;
use PHPUnit\TextUI\Output\Default\ProgressPrinter\ProgressPrinter as DefaultProgressPrinter;
use PHPUnit\TextUI\Output\Default\ResultPrinter as DefaultResultPrinter;
use PHPUnit\TextUI\Output\Default\UnexpectedOutputPrinter;
use PHPUnit\TextUI\Output\TestDox\ResultPrinter as TestDoxResultPrinter;
use SebastianBergmann\Timer\Duration;
use SebastianBergmann\Timer\ResourceUsageFormatter;
Expand All @@ -46,6 +47,8 @@ public static function init(Configuration $configuration, bool $extensionReplace

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

self::createUnexpectedOutputPrinter();

if (!$extensionReplacesProgressOutput) {
self::createProgressPrinter($configuration);
}
Expand Down Expand Up @@ -251,4 +254,15 @@ private static function createSummaryPrinter(Configuration $configuration): void
$configuration->colors(),
);
}

/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
private static function createUnexpectedOutputPrinter(): void
{
assert(self::$printer !== null);

new UnexpectedOutputPrinter(self::$printer, EventFacade::instance());
}
}
23 changes: 23 additions & 0 deletions tests/end-to-end/_files/UnexpectedOutputTest.php
@@ -0,0 +1,23 @@
<?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;

use function var_dump;
use PHPUnit\Framework\TestCase;

final class UnexpectedOutputTest extends TestCase
{
public function testSomething(): void
{
var_dump(['foo' => 'bar']);

$this->assertSame('something', 'something');
}
}
@@ -0,0 +1,24 @@
--TEST--
phpunit ../../_files/UnexpectedOutputTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/UnexpectedOutputTest.php';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

array(1) {
["foo"]=>
string(3) "bar"
}
. 1 / 1 (100%)

Time: %s, Memory: %s

OK (1 test, 1 assertion)
@@ -0,0 +1,23 @@
--TEST--
phpunit ../../_files/UnexpectedOutputTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-progress';
$_SERVER['argv'][] = __DIR__ . '/../_files/UnexpectedOutputTest.php';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

array(1) {
["foo"]=>
string(3) "bar"
}
Time: %s, Memory: %s

OK (1 test, 1 assertion)

0 comments on commit fd57d97

Please sign in to comment.