mirror of
https://github.com/pestphp/pest.git
synced 2026-12-06 15:52:16 +01:00
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:
@@ -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,
|
||||
|
||||
@@ -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';
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user