Skip to content

Commit

Permalink
Closes #5219
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 19, 2023
1 parent e90bbf9 commit 74ce5b6
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## [10.0.10] - 2023-MM-DD

### Fixed

* [#5219](https://github.com/sebastianbergmann/phpunit/issues/5219): Exceptions thrown in event subscribers affect how tests are run and/or how their outcome is evaluated

## [10.0.9] - 2023-02-19

### Fixed
Expand Down Expand Up @@ -196,6 +202,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
* PHP 7.3, PHP 7.4, and PHP 8.0 are no longer supported
* `phpunit/php-code-coverage` [no longer supports PHPDBG and Xdebug 2](https://github.com/sebastianbergmann/php-code-coverage/blob/10.0.0/ChangeLog.md#1000---2023-02-03)

[10.0.10]: https://github.com/sebastianbergmann/phpunit/compare/10.0.9...10.0
[10.0.9]: https://github.com/sebastianbergmann/phpunit/compare/10.0.8...10.0.9
[10.0.8]: https://github.com/sebastianbergmann/phpunit/compare/10.0.7...10.0.8
[10.0.7]: https://github.com/sebastianbergmann/phpunit/compare/10.0.6...10.0.7
Expand Down
25 changes: 23 additions & 2 deletions src/Event/Dispatcher/DirectDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
namespace PHPUnit\Event;

use function array_key_exists;
use function dirname;
use function sprintf;
use function str_starts_with;
use Throwable;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -80,15 +83,33 @@ public function dispatch(Event $event): void
}

foreach ($this->tracers as $tracer) {
$tracer->trace($event);
try {
$tracer->trace($event);
} catch (Throwable $t) {
$this->ignoreThrowablesFromThirdPartySubscribers($t);
}
}

if (!array_key_exists($eventClassName, $this->subscribers)) {
return;
}

foreach ($this->subscribers[$eventClassName] as $subscriber) {
$subscriber->notify($event);
try {
$subscriber->notify($event);
} catch (Throwable $t) {
$this->ignoreThrowablesFromThirdPartySubscribers($t);
}
}
}

/**
* @throws Throwable
*/
private function ignoreThrowablesFromThirdPartySubscribers(Throwable $t): void
{
if (str_starts_with($t->getFile(), dirname(__DIR__, 2))) {
throw $t;
}
}
}
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/5219.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5219
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--configuration';
$_SERVER['argv'][] = __DIR__ . '/5219/phpunit.xml';

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

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

Runtime: %s
Configuration: %s

. 1 / 1 (100%)

Time: %s, Memory: %s MB

OK (1 test, 1 assertion)
14 changes: 14 additions & 0 deletions tests/end-to-end/regression/5219/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../phpunit.xsd"
bootstrap="src/autoload.php">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<extensions>
<bootstrap class="PHPUnit\TestFixture\Issue5219\Extension"/>
</extensions>
</phpunit>
23 changes: 23 additions & 0 deletions tests/end-to-end/regression/5219/src/Extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5219;

use PHPUnit\Runner\Extension\Extension as ExtensionInterface;
use PHPUnit\Runner\Extension\Facade;
use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration;

final class Extension implements ExtensionInterface
{
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
{
$facade->registerSubscriber(new TestPreparedSubscriber);
}
}
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/5219/src/TestPreparedSubscriber.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 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5219;

use PHPUnit\Event\Test\Prepared;
use PHPUnit\Event\Test\PreparedSubscriber;
use RuntimeException;

final class TestPreparedSubscriber implements PreparedSubscriber
{
public function notify(Prepared $event): void
{
throw new RuntimeException('message');
}
}
14 changes: 14 additions & 0 deletions tests/end-to-end/regression/5219/src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5219;

require __DIR__ . '/Extension.php';

require __DIR__ . '/TestPreparedSubscriber.php';
20 changes: 20 additions & 0 deletions tests/end-to-end/regression/5219/tests/Issue5219Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5219;

use PHPUnit\Framework\TestCase;

final class Issue5219Test extends TestCase
{
public function testOne(): void
{
$this->assertTrue(true);
}
}

0 comments on commit 74ce5b6

Please sign in to comment.