forked from sebastianbergmann/phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report exceptions thrown by third-party event subscribers as test run…
…ner warnings
- Loading branch information
1 parent
8aa37e3
commit 0a0f2e4
Showing
8 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/end-to-end/extension/_files/exception-in-extension-subscriber/phpunit.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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"> | ||
<extensions> | ||
<bootstrap class="PHPUnit\TestFixture\Event\MyExtension\MyExtensionBootstrap"> | ||
<parameter name="message" value="the-message"/> | ||
</bootstrap> | ||
</extensions> | ||
|
||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
22 changes: 22 additions & 0 deletions
22
.../extension/_files/exception-in-extension-subscriber/src/MyExecutionFinishedSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\Event\MyExtension; | ||
|
||
use PHPUnit\Event\TestRunner\ExecutionFinished; | ||
use PHPUnit\Event\TestRunner\ExecutionFinishedSubscriber; | ||
use RuntimeException; | ||
|
||
final class MyExecutionFinishedSubscriber implements ExecutionFinishedSubscriber | ||
{ | ||
public function notify(ExecutionFinished $event): void | ||
{ | ||
throw new RuntimeException('message'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...nd-to-end/extension/_files/exception-in-extension-subscriber/src/MyExtensionBootstrap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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\Event\MyExtension; | ||
|
||
use PHPUnit\Runner\Extension\Extension; | ||
use PHPUnit\Runner\Extension\Facade; | ||
use PHPUnit\Runner\Extension\ParameterCollection; | ||
use PHPUnit\TextUI\Configuration\Configuration; | ||
|
||
final class MyExtensionBootstrap implements Extension | ||
{ | ||
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void | ||
{ | ||
$facade->registerSubscriber(new MyExecutionFinishedSubscriber); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/end-to-end/extension/_files/exception-in-extension-subscriber/src/autoload.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?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. | ||
*/ | ||
require __DIR__ . '/MyExtensionBootstrap.php'; | ||
|
||
require __DIR__ . '/MyExecutionFinishedSubscriber.php'; |
20 changes: 20 additions & 0 deletions
20
tests/end-to-end/extension/_files/exception-in-extension-subscriber/tests/Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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\Event\MyExtension; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class Test extends TestCase | ||
{ | ||
public function testOne(): void | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/end-to-end/extension/exception-in-extension-subscriber.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
Test runner warning is triggered when an exception is triggered in an extension's event subscriber | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/_files/exception-in-extension-subscriber/phpunit.xml'; | ||
|
||
require __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 | ||
|
||
There was 1 PHPUnit test runner warning: | ||
|
||
1) Exception in third-party event subscriber: message | ||
%A | ||
|
||
WARNINGS! | ||
Tests: 1, Assertions: 1, Warnings: 1. |