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 ParaTest\WrapperRunner\WrapperWorker;
use Pest\ConfigLoader; use Pest\ConfigLoader;
use Pest\Kernel; use Pest\Kernel;
use Pest\Plugins\Actions\CallsAddsOutput;
use Pest\Plugins\Actions\CallsHandleArguments; use Pest\Plugins\Actions\CallsHandleArguments;
use Pest\Support\Container; use Pest\Support\Container;
use Pest\TestSuite; use Pest\TestSuite;

View File

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

View File

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

View File

@ -37,17 +37,17 @@ final class Laravel
private function setLaravelParallelRunner(): void 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.'); 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 private static function isALaravelApplication(): bool
{ {
return class_exists(\Illuminate\Foundation\Application::class) return class_exists(\Illuminate\Foundation\Application::class)
&& class_exists(\Illuminate\Testing\ParallelRunner::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\Concerns\HandleArguments;
use Pest\Plugins\Parallel\Paratest\WrapperRunner; use Pest\Plugins\Parallel\Paratest\WrapperRunner;
use Symfony\Component\Console\Input\ArgvInput;
/** /**
* @internal * @internal
@ -14,6 +13,7 @@ use Symfony\Component\Console\Input\ArgvInput;
final class Parallel final class Parallel
{ {
use HandleArguments; use HandleArguments;
/** /**
* @var string[] * @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); $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; 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\Coverage\CoverageMerger;
use ParaTest\JUnit\LogMerger; use ParaTest\JUnit\LogMerger;
use ParaTest\JUnit\Writer; use ParaTest\JUnit\Writer;
@ -19,49 +28,47 @@ use PHPUnit\TestRunner\TestResult\TestResult;
use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry; use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry;
use PHPUnit\TextUI\ShellExitCodeCalculator; use PHPUnit\TextUI\ShellExitCodeCalculator;
use PHPUnit\Util\ExcludeList; use PHPUnit\Util\ExcludeList;
use function realpath;
use SebastianBergmann\Timer\Timer; use SebastianBergmann\Timer\Timer;
use SplFileInfo; use SplFileInfo;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder; 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 unlink;
use function unserialize; use function unserialize;
use function usleep; use function usleep;
use const DIRECTORY_SEPARATOR;
/** @internal */ /** @internal */
final class WrapperRunner implements RunnerInterface final class WrapperRunner implements RunnerInterface
{ {
private const CYCLE_SLEEP = 10000; private const CYCLE_SLEEP = 10000;
private readonly ResultPrinter $printer; private readonly ResultPrinter $printer;
private readonly Timer $timer; private readonly Timer $timer;
/** @var non-empty-string[] */ /** @var non-empty-string[] */
private array $pending = []; private array $pending = [];
private int $exitcode = -1;
private int $exitcode = -1;
/** @var array<positive-int,WrapperWorker> */ /** @var array<positive-int,WrapperWorker> */
private array $workers = []; private array $workers = [];
/** @var array<int,int> */ /** @var array<int,int> */
private array $batches = []; private array $batches = [];
/** @var list<SplFileInfo> */ /** @var list<SplFileInfo> */
private array $testresultFiles = []; private array $testresultFiles = [];
/** @var list<SplFileInfo> */ /** @var list<SplFileInfo> */
private array $coverageFiles = []; private array $coverageFiles = [];
/** @var list<SplFileInfo> */ /** @var list<SplFileInfo> */
private array $junitFiles = []; private array $junitFiles = [];
/** @var list<SplFileInfo> */ /** @var list<SplFileInfo> */
private array $teamcityFiles = []; private array $teamcityFiles = [];
/** @var list<SplFileInfo> */ /** @var list<SplFileInfo> */
private array $testdoxFiles = []; private array $testdoxFiles = [];
@ -78,12 +85,12 @@ final class WrapperRunner implements RunnerInterface
$this->timer = new Timer(); $this->timer = new Timer();
$wrapper = realpath( $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); assert($wrapper !== false);
$phpFinder = new PhpExecutableFinder(); $phpFinder = new PhpExecutableFinder();
$phpBin = $phpFinder->find(false); $phpBin = $phpFinder->find(false);
assert($phpBin !== false); assert($phpBin !== false);
$parameters = [$phpBin]; $parameters = [$phpBin];
$parameters = array_merge($parameters, $phpFinder->findArguments()); $parameters = array_merge($parameters, $phpFinder->findArguments());
@ -100,13 +107,16 @@ final class WrapperRunner implements RunnerInterface
public function run(): int public function run(): int
{ {
ExcludeList::addDirectory(dirname(__DIR__)); $directory = dirname(__DIR__);
assert(strlen($directory) > 0);
ExcludeList::addDirectory($directory);
TestResultFacade::init(); TestResultFacade::init();
EventFacade::seal(); 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); $this->pending = $this->getTestFiles($suiteLoader);
$result = TestResultFacade::result(); $result = TestResultFacade::result();
$this->printer->setTestCount($suiteLoader->testCount); $this->printer->setTestCount($suiteLoader->testCount);
$this->printer->start(); $this->printer->start();
@ -122,7 +132,7 @@ final class WrapperRunner implements RunnerInterface
private function startWorkers(): void private function startWorkers(): void
{ {
for ($token = 1; $token <= $this->options->processes; ++$token) { for ($token = 1; $token <= $this->options->processes; $token++) {
$this->startWorker($token); $this->startWorker($token);
} }
} }
@ -143,7 +153,7 @@ final class WrapperRunner implements RunnerInterface
$this->flushWorker($worker); $this->flushWorker($worker);
if ($batchSize !== null && $batchSize !== 0 && $this->batches[$token] === $batchSize) { if ($batchSize !== 0 && $this->batches[$token] === $batchSize) {
$this->destroyWorker($token); $this->destroyWorker($token);
$worker = $this->startWorker($token); $worker = $this->startWorker($token);
} }
@ -339,7 +349,7 @@ final class WrapperRunner implements RunnerInterface
); );
} }
/** @param list<SplFileInfo> $files */ /** @param list<SplFileInfo> $files */
private function clearFiles(array $files): void private function clearFiles(array $files): void
{ {
foreach ($files as $file) { foreach ($files as $file) {
@ -357,11 +367,11 @@ final class WrapperRunner implements RunnerInterface
*/ */
private function getTestFiles(SuiteLoader $suiteLoader): array 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( $tests = array_filter(
$suiteLoader->files, $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()]; return [...$tests, ...TestSuite::getInstance()->tests->getFilenames()];

View File

@ -82,7 +82,7 @@ final class StateGenerator
$state->add(TestResult::fromTestCase( $state->add(TestResult::fromTestCase(
new TestMethod( new TestMethod(
/** @phpstan-ignore-next-line */ /** @phpstan-ignore-next-line */
"$i", "$i",
/** @phpstan-ignore-next-line */ /** @phpstan-ignore-next-line */
'', '',