fix: let extensions register event subscribers in --parallel mode (#2002)

Co-authored-by: Aleksandr Štšepelin <as@jp.ee>
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
ChrisAbner
2026-11-03 10:51:33 -05:00
committed by GitHub
parent e5906a50cf
commit 9a77ff6b96
7 changed files with 62 additions and 3 deletions
@@ -160,8 +160,6 @@ final class WrapperRunner implements RunnerInterface
{
$directory = dirname(__DIR__);
ExcludeList::addDirectory($directory);
TestResultFacade::init();
EventFacade::instance()->seal();
$suiteLoader = new SuiteLoader(
$this->options,
$this->output,
+2 -1
View File
@@ -2266,6 +2266,7 @@
✓ parallel
✓ a parallel test can extend another test with same name
✓ parallel reports invalid datasets as failures
✓ parallel lets extensions register event subscribers
✓ parallel can have multiple exclude-groups
✓ parallel can have multiple groups
@@ -2301,4 +2302,4 @@
✓ pass with dataset with ('my-datas-set-value')
✓ within describe → pass with dataset with ('my-datas-set-value')
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1628 passed (3596 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1629 passed (3599 assertions)
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="ParallelExtensionSubscriber/bootstrap.php"
colors="true"
>
<testsuites>
<testsuite name="default">
<file>ParallelExtensionSubscriber/PassingTest.php</file>
</testsuite>
</testsuites>
<extensions>
<bootstrap class="Tests\Fixtures\Suites\ParallelExtensionSubscriber\SubscribingExtension"/>
</extensions>
</phpunit>
@@ -0,0 +1,3 @@
<?php
it('passes')->assertTrue(true);
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Tests\Fixtures\Suites\ParallelExtensionSubscriber;
use PHPUnit\Event\Test\Prepared;
use PHPUnit\Event\Test\PreparedSubscriber;
use PHPUnit\Runner\Extension\Extension;
use PHPUnit\Runner\Extension\Facade;
use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration;
final class SubscribingExtension implements Extension
{
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
{
$facade->registerSubscriber(new class implements PreparedSubscriber
{
public function notify(Prepared $event): void {}
});
}
}
@@ -0,0 +1,4 @@
<?php
require __DIR__.'/../../../../vendor/autoload.php';
require __DIR__.'/SubscribingExtension.php';
+15
View File
@@ -38,6 +38,21 @@ test('parallel reports invalid datasets as failures', function () use ($run): vo
->toContain('Parallel: 3 processes');
})->skipOnWindows();
test('parallel lets extensions register event subscribers', function (): void {
$process = new Process(
['php', 'bin/pest', '--configuration', 'tests/Fixtures/Suites/ParallelExtensionSubscriber.xml', '--parallel', '--processes=2'],
dirname(__DIR__, 2),
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
);
$process->run();
expect($process->getExitCode())->toBe(0)
->and(removeAnsiEscapeSequences($process->getOutput()))
->not->toContain('failed')
->toContain('Parallel: 2 processes');
})->skipOnWindows();
test('parallel can have multiple exclude-groups', function () use ($run): void {
$singleExclude = $run('--exclude-group=integration');
$doubleExclude = $run('--exclude-group=integration', '--exclude-group=container');