diff --git a/src/WrapperRunner/WrapperRunner.php b/src/WrapperRunner/WrapperRunner.php index 6676c48d..6982d818 100644 --- a/src/WrapperRunner/WrapperRunner.php +++ b/src/WrapperRunner/WrapperRunner.php @@ -49,6 +49,10 @@ final class WrapperRunner implements RunnerInterface /** @var array */ private array $batches = []; + /** @var list */ + private array $statusFiles = []; + /** @var list */ + private array $progressFiles = []; /** @var list */ private array $testresultFiles = []; /** @var list */ @@ -204,7 +208,10 @@ private function startWorker(int $token): WrapperWorker $worker->start(); $this->batches[$token] = 0; + $this->statusFiles[] = $worker->statusFile; + $this->progressFiles[] = $worker->progressFile; $this->testresultFiles[] = $worker->testresultFile; + if (isset($worker->junitFile)) { $this->junitFiles[] = $worker->junitFile; } @@ -289,6 +296,8 @@ private function complete(TestResult $testResultSum): int $testResultSum, ); + $this->clearFiles($this->statusFiles); + $this->clearFiles($this->progressFiles); $this->clearFiles($this->testresultFiles); $this->clearFiles($this->coverageFiles); $this->clearFiles($this->junitFiles); diff --git a/src/WrapperRunner/WrapperWorker.php b/src/WrapperRunner/WrapperWorker.php index 1030997c..a6d9c5f5 100644 --- a/src/WrapperRunner/WrapperWorker.php +++ b/src/WrapperRunner/WrapperWorker.php @@ -30,19 +30,19 @@ final class WrapperWorker { public const COMMAND_EXIT = "EXIT\n"; + public readonly SplFileInfo $statusFile; public readonly SplFileInfo $progressFile; public readonly SplFileInfo $testresultFile; public readonly SplFileInfo $junitFile; public readonly SplFileInfo $coverageFile; public readonly SplFileInfo $teamcityFile; - public readonly SplFileInfo $testdoxFile; + public readonly SplFileInfo $testdoxFile; private ?string $currentlyExecuting = null; private Process $process; private int $inExecution = 0; private InputStream $input; private int $exitCode = -1; - private string $statusFilepath; /** @param non-empty-string[] $parameters */ public function __construct( @@ -51,15 +51,15 @@ public function __construct( array $parameters, private readonly int $token ) { - $commonTmpFilePath = sprintf( + $commonTmpFilePath = sprintf( '%s%sworker_%02s_stdout_%s_', $options->tmpDir, DIRECTORY_SEPARATOR, $token, uniqid(), ); - $this->statusFilepath = $commonTmpFilePath . 'status'; - touch($this->statusFilepath); + $this->statusFile = new SplFileInfo($commonTmpFilePath . 'status'); + touch($this->statusFile->getPathname()); $this->progressFile = new SplFileInfo($commonTmpFilePath . 'progress'); touch($this->progressFile->getPathname()); $this->testresultFile = new SplFileInfo($commonTmpFilePath . 'testresult'); @@ -80,7 +80,7 @@ public function __construct( } $parameters[] = '--status-file'; - $parameters[] = $this->statusFilepath; + $parameters[] = $this->statusFile->getPathname(); $parameters[] = '--progress-file'; $parameters[] = $this->progressFile->getPathname(); $parameters[] = '--testresult-file'; @@ -181,12 +181,13 @@ public function stop(): void public function isFree(): bool { - clearstatcache(true, $this->statusFilepath); + $statusFilepath = $this->statusFile->getPathname(); + clearstatcache(true, $statusFilepath); - $isFree = $this->inExecution === filesize($this->statusFilepath); + $isFree = $this->inExecution === filesize($statusFilepath); if ($isFree && $this->inExecution > 0) { - $exitCodes = file_get_contents($this->statusFilepath); + $exitCodes = file_get_contents($statusFilepath); assert(is_string($exitCodes) && $exitCodes !== ''); $this->exitCode = (int) $exitCodes[-1]; } diff --git a/test/TestBase.php b/test/TestBase.php index 9b3f3b1b..64a2e028 100644 --- a/test/TestBase.php +++ b/test/TestBase.php @@ -25,8 +25,7 @@ abstract class TestBase extends TestCase protected string $runnerClass = WrapperRunner::class; /** @var array */ protected array $bareOptions = []; - /** @var string */ - protected $tmpDir; + protected string $tmpDir; final protected function setUp(): void { diff --git a/test/Unit/WrapperRunner/WrapperRunnerTest.php b/test/Unit/WrapperRunner/WrapperRunnerTest.php index 66f9dc86..85f16df5 100644 --- a/test/Unit/WrapperRunner/WrapperRunnerTest.php +++ b/test/Unit/WrapperRunner/WrapperRunnerTest.php @@ -23,6 +23,7 @@ use function defined; use function file_get_contents; use function file_put_contents; +use function glob; use function min; use function posix_mkfifo; use function preg_match; @@ -468,6 +469,9 @@ public function testRunningFewerTestsThanTheWorkersIsPossible(): void $runnerResult = $this->runRunner(); self::assertEquals(0, $runnerResult->exitCode); + $glob = glob($this->tmpDir . '/*'); + self::assertNotFalse($glob); + self::assertCount(0, $glob); } public function testResultsAreCorrect(): void