From 5f3d0f2124464fe3039dd6d1a7f39409ef49e2d8 Mon Sep 17 00:00:00 2001 From: Morten Harders Date: Sun, 11 Oct 2026 19:12:40 +0200 Subject: [PATCH] fix: support brianium/paratest 7.26.1 worker tmp dir (#1959) paratest 7.26.1 added a required $tmpDir argument to WrapperWorker and keeps worker files in a private per-run directory. Create that 0700 directory per run, pass it to each worker and remove it on completion. Require paratest ^7.26.1. --- composer.json | 2 +- .../Parallel/Paratest/WrapperRunner.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ad9e7cdd..10070ea1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^8.4", - "brianium/paratest": "^7.26.0", + "brianium/paratest": "^7.26.1", "nunomaduro/collision": "^8.9.5", "nunomaduro/termwind": "^2.4.0", "pestphp/pest-plugin": "^5.0.0", diff --git a/src/Plugins/Parallel/Paratest/WrapperRunner.php b/src/Plugins/Parallel/Paratest/WrapperRunner.php index 87d4515f..b89191ed 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -27,6 +27,7 @@ use PHPUnit\TestRunner\TestResult\TestResult; use PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry; use PHPUnit\Util\ExcludeList; use ReflectionProperty; +use RuntimeException; use SebastianBergmann\CodeCoverage\Node\Builder; use SebastianBergmann\CodeCoverage\Serialization\Merger; use SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser; @@ -41,13 +42,18 @@ use function array_merge; use function array_merge_recursive; use function array_shift; use function assert; +use function bin2hex; use function count; use function dirname; use function file_get_contents; use function filesize; use function is_file; use function max; +use function mkdir; +use function random_bytes; use function realpath; +use function rmdir; +use function sprintf; use function str_starts_with; use function unlink; use function unserialize; @@ -115,6 +121,9 @@ final class WrapperRunner implements RunnerInterface private CodeCoverageFilterRegistry $codeCoverageFilterRegistry; + /** @var non-empty-string */ + private string $runTmpDir; + public function __construct( private readonly Options $options, private readonly OutputInterface $output @@ -164,6 +173,7 @@ final class WrapperRunner implements RunnerInterface $this->timer->start(); + $this->runTmpDir = $this->createPrivateRunTmpDir(); $this->startWorkers(); $this->assignAllPendingTests(); $this->waitForAllToFinish(); @@ -197,6 +207,23 @@ final class WrapperRunner implements RunnerInterface return array_merge($parameters, ['-d', 'pcov.directory='.TestSuite::getInstance()->rootPath]); } + /** @return non-empty-string */ + private function createPrivateRunTmpDir(): string + { + $runTmpDir = sprintf( + '%s%spest_%s', + $this->options->tmpDir, + DIRECTORY_SEPARATOR, + bin2hex(random_bytes(16)), + ); + + if (! @mkdir($runTmpDir, 0700)) { + throw new RuntimeException(sprintf('Unable to create private temporary directory "%s"', $runTmpDir)); + } + + return $runTmpDir; + } + private function startWorkers(): void { for ($token = 1; $token <= $this->options->processes; $token++) { @@ -297,6 +324,7 @@ final class WrapperRunner implements RunnerInterface $this->options, $this->parameters, $token, + $this->runTmpDir, ); $worker->start(); $this->batches[$token] = 0; @@ -496,6 +524,7 @@ final class WrapperRunner implements RunnerInterface $this->clearFiles($this->junitFiles); $this->clearFiles($this->teamcityFiles); $this->clearFiles($this->testdoxFiles); + rmdir($this->runTmpDir); return $exitcode; }