This commit is contained in:
Luke Downing
2023-02-08 13:48:42 +00:00
committed by Nuno Maduro
parent dd840f8861
commit a34001faf0
7 changed files with 45 additions and 41 deletions

View File

@ -6,7 +6,6 @@ use ParaTest\WrapperRunner\ApplicationForWrapperWorker;
use ParaTest\WrapperRunner\WrapperWorker;
use Pest\ConfigLoader;
use Pest\Kernel;
use Pest\Plugins\Actions\CallsAddsOutput;
use Pest\Plugins\Actions\CallsHandleArguments;
use Pest\Support\Container;
use Pest\TestSuite;

View File

@ -5,21 +5,14 @@ declare(strict_types=1);
namespace Pest\Logging\TeamCity;
use NunoMaduro\Collision\Adapters\Phpunit\State;
use NunoMaduro\Collision\Adapters\Phpunit\TestResult;
use Pest\Exceptions\ShouldNotHappen;
use Pest\Support\StateGenerator;
use Pest\Support\Str;
use PHPUnit\Event\Code\Test;
use PHPUnit\Event\Code\TestDox;
use PHPUnit\Event\Code\TestMethod;
use PHPUnit\Event\Code\Throwable;
use PHPUnit\Event\Test\Errored;
use PHPUnit\Event\TestData\TestDataCollection;
use PHPUnit\Event\TestSuite\TestSuite;
use PHPUnit\Framework\Exception as FrameworkException;
use PHPUnit\Framework\IncompleteTestError;
use PHPUnit\Framework\SkippedWithMessageException;
use PHPUnit\Metadata\MetadataCollection;
use PHPUnit\TestRunner\TestResult\TestResult as PhpUnitTestResult;
/**

View File

@ -1,20 +1,21 @@
<?php
declare(strict_types=1);
namespace Pest\Plugins;
use ParaTest\ParaTestCommand;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Plugins\Actions\CallsAddsOutput;
use Pest\Plugins\Concerns\HandleArguments;
use Pest\Plugins\Parallel\Handlers\Laravel;
use Pest\Support\Arr;
use Pest\Support\Container;
use Pest\TestSuite;
use function Pest\version;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;
use function Pest\version;
final class Parallel implements HandlesArguments
{
@ -22,7 +23,7 @@ final class Parallel implements HandlesArguments
private const HANDLERS = [
Parallel\Handlers\Parallel::class,
Laravel::class,
Parallel\Handlers\Laravel::class,
];
public function handleArguments(array $arguments): array
@ -41,6 +42,7 @@ final class Parallel implements HandlesArguments
if ($this->hasArgument('--parallel', $arguments)) {
return true;
}
return $this->hasArgument('-p', $arguments);
}
@ -54,7 +56,7 @@ final class Parallel implements HandlesArguments
$filteredArguments = array_reduce(
self::HANDLERS,
fn($arguments, $handler) => (new $handler())->handle($arguments),
fn ($arguments, $handler) => (new $handler())->handle($arguments),
$arguments
);

View File

@ -37,17 +37,17 @@ final class Laravel
private function setLaravelParallelRunner(): void
{
if (!method_exists(ParallelRunner::class, 'resolveRunnerUsing')) {
if (! method_exists(ParallelRunner::class, 'resolveRunnerUsing')) {
exit('Using parallel with Pest requires Laravel v8.55.0 or higher.');
}
ParallelRunner::resolveRunnerUsing(fn(Options $options, OutputInterface $output): RunnerInterface => new WrapperRunner($options, $output));
ParallelRunner::resolveRunnerUsing(fn (Options $options, OutputInterface $output): RunnerInterface => new WrapperRunner($options, $output));
}
private static function isALaravelApplication(): bool
{
return class_exists(\Illuminate\Foundation\Application::class)
&& class_exists(\Illuminate\Testing\ParallelRunner::class)
&& !class_exists(\Orchestra\Testbench\TestCase::class);
&& ! class_exists(\Orchestra\Testbench\TestCase::class);
}
}

View File

@ -6,7 +6,6 @@ namespace Pest\Plugins\Parallel\Handlers;
use Pest\Plugins\Concerns\HandleArguments;
use Pest\Plugins\Parallel\Paratest\WrapperRunner;
use Symfony\Component\Console\Input\ArgvInput;
/**
* @internal
@ -14,6 +13,7 @@ use Symfony\Component\Console\Input\ArgvInput;
final class Parallel
{
use HandleArguments;
/**
* @var string[]
*/
@ -27,6 +27,6 @@ final class Parallel
{
$args = array_reduce(self::ARGS_TO_REMOVE, fn ($args, $arg): array => $this->popArgument($arg, $args), $args);
return $this->pushArgument('--runner=' . WrapperRunner::class, $args);
return $this->pushArgument('--runner='.WrapperRunner::class, $args);
}
}

View File

@ -4,6 +4,15 @@ declare(strict_types=1);
namespace Pest\Plugins\Parallel\Paratest;
use function array_merge;
use function array_merge_recursive;
use function array_shift;
use function assert;
use function count;
use const DIRECTORY_SEPARATOR;
use function dirname;
use function file_get_contents;
use function max;
use ParaTest\Coverage\CoverageMerger;
use ParaTest\JUnit\LogMerger;
use ParaTest\JUnit\Writer;
@ -19,49 +28,47 @@ use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry;
use PHPUnit\TextUI\ShellExitCodeCalculator;
use PHPUnit\Util\ExcludeList;
use function realpath;
use SebastianBergmann\Timer\Timer;
use SplFileInfo;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder;
use function array_merge;
use function array_merge_recursive;
use function array_shift;
use function assert;
use function count;
use function dirname;
use function file_get_contents;
use function max;
use function realpath;
use function unlink;
use function unserialize;
use function usleep;
use const DIRECTORY_SEPARATOR;
/** @internal */
final class WrapperRunner implements RunnerInterface
{
private const CYCLE_SLEEP = 10000;
private readonly ResultPrinter $printer;
private readonly Timer $timer;
/** @var non-empty-string[] */
private array $pending = [];
private int $exitcode = -1;
/** @var array<positive-int,WrapperWorker> */
private array $workers = [];
/** @var array<int,int> */
private array $batches = [];
/** @var list<SplFileInfo> */
private array $testresultFiles = [];
/** @var list<SplFileInfo> */
private array $coverageFiles = [];
/** @var list<SplFileInfo> */
private array $junitFiles = [];
/** @var list<SplFileInfo> */
private array $teamcityFiles = [];
/** @var list<SplFileInfo> */
private array $testdoxFiles = [];
@ -78,7 +85,7 @@ final class WrapperRunner implements RunnerInterface
$this->timer = new Timer();
$wrapper = realpath(
dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'pest-wrapper.php',
dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'pest-wrapper.php',
);
assert($wrapper !== false);
@ -100,10 +107,13 @@ final class WrapperRunner implements RunnerInterface
public function run(): int
{
ExcludeList::addDirectory(dirname(__DIR__));
$directory = dirname(__DIR__);
assert(strlen($directory) > 0);
ExcludeList::addDirectory($directory);
TestResultFacade::init();
EventFacade::seal();
$suiteLoader = new SuiteLoader($this->options, $this->output, $this->codeCoverageFilterRegistry,);
$suiteLoader = new SuiteLoader($this->options, $this->output, $this->codeCoverageFilterRegistry);
$this->pending = $this->getTestFiles($suiteLoader);
$result = TestResultFacade::result();
@ -122,7 +132,7 @@ final class WrapperRunner implements RunnerInterface
private function startWorkers(): void
{
for ($token = 1; $token <= $this->options->processes; ++$token) {
for ($token = 1; $token <= $this->options->processes; $token++) {
$this->startWorker($token);
}
}
@ -143,7 +153,7 @@ final class WrapperRunner implements RunnerInterface
$this->flushWorker($worker);
if ($batchSize !== null && $batchSize !== 0 && $this->batches[$token] === $batchSize) {
if ($batchSize !== 0 && $this->batches[$token] === $batchSize) {
$this->destroyWorker($token);
$worker = $this->startWorker($token);
}
@ -357,11 +367,11 @@ final class WrapperRunner implements RunnerInterface
*/
private function getTestFiles(SuiteLoader $suiteLoader): array
{
$this->debug(sprintf("Found %d test file%s", count($suiteLoader->files), count($suiteLoader->files) === 1 ? '' : 's'));
$this->debug(sprintf('Found %d test file%s', count($suiteLoader->files), count($suiteLoader->files) === 1 ? '' : 's'));
$tests = array_filter(
$suiteLoader->files,
fn(string $filename): bool => ! str_ends_with($filename, "eval()'d code")
fn (string $filename): bool => ! str_ends_with($filename, "eval()'d code")
);
return [...$tests, ...TestSuite::getInstance()->tests->getFilenames()];