diff --git a/bin/pest-wrapper.php b/bin/pest-wrapper.php index 49f21966..c32d9e1f 100644 --- a/bin/pest-wrapper.php +++ b/bin/pest-wrapper.php @@ -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; diff --git a/src/Logging/TeamCity/Converter.php b/src/Logging/TeamCity/Converter.php index 0a1e592e..1f0de446 100644 --- a/src/Logging/TeamCity/Converter.php +++ b/src/Logging/TeamCity/Converter.php @@ -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; /** diff --git a/src/Plugins/Parallel.php b/src/Plugins/Parallel.php index f7d308ce..d7465b62 100644 --- a/src/Plugins/Parallel.php +++ b/src/Plugins/Parallel.php @@ -1,20 +1,21 @@ 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 ); diff --git a/src/Plugins/Parallel/Handlers/Laravel.php b/src/Plugins/Parallel/Handlers/Laravel.php index 9d05a8fd..46d20c6b 100644 --- a/src/Plugins/Parallel/Handlers/Laravel.php +++ b/src/Plugins/Parallel/Handlers/Laravel.php @@ -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); } } diff --git a/src/Plugins/Parallel/Handlers/Parallel.php b/src/Plugins/Parallel/Handlers/Parallel.php index 0ff58839..8a5199b0 100644 --- a/src/Plugins/Parallel/Handlers/Parallel.php +++ b/src/Plugins/Parallel/Handlers/Parallel.php @@ -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); } } diff --git a/src/Plugins/Parallel/Paratest/WrapperRunner.php b/src/Plugins/Parallel/Paratest/WrapperRunner.php index 9d2dd3b2..7424152e 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -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; + + private int $exitcode = -1; + /** @var array */ private array $workers = []; + /** @var array */ private array $batches = []; /** @var list */ private array $testresultFiles = []; + /** @var list */ private array $coverageFiles = []; + /** @var list */ private array $junitFiles = []; + /** @var list */ private array $teamcityFiles = []; + /** @var list */ private array $testdoxFiles = []; @@ -78,12 +85,12 @@ 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); $phpFinder = new PhpExecutableFinder(); - $phpBin = $phpFinder->find(false); + $phpBin = $phpFinder->find(false); assert($phpBin !== false); $parameters = [$phpBin]; $parameters = array_merge($parameters, $phpFinder->findArguments()); @@ -100,13 +107,16 @@ 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(); + $result = TestResultFacade::result(); $this->printer->setTestCount($suiteLoader->testCount); $this->printer->start(); @@ -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); } @@ -339,7 +349,7 @@ final class WrapperRunner implements RunnerInterface ); } - /** @param list $files */ + /** @param list $files */ private function clearFiles(array $files): void { foreach ($files as $file) { @@ -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()]; diff --git a/src/Support/StateGenerator.php b/src/Support/StateGenerator.php index a78d499e..21bd1794 100644 --- a/src/Support/StateGenerator.php +++ b/src/Support/StateGenerator.php @@ -82,7 +82,7 @@ final class StateGenerator $state->add(TestResult::fromTestCase( new TestMethod( - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line */ "$i", /** @phpstan-ignore-next-line */ '',