From 57862bbb91e51ff7dd86ae3f5ff5134aaba4819b Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 3 Oct 2024 09:43:49 +0200 Subject: [PATCH] Avoid passing incompatible options to chunked PHPUnit executions --- CHANGELOG.md | 3 ++ src/Process/CommandLine.php | 4 +++ tests/Unit/Process/CommandLineTest.php | 47 ++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a1b4cc..06a86c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased +## [1.3.1] - 2024-10-03 + * Avoid passing `--testsuite` option to PHPUnit when running with chunks [#276](https://github.com/facile-it/paraunit/pull/276) + ## [1.3.0] - 2022-06-15 ### Added * Add `--chunk-size` option [#164](https://github.com/facile-it/paraunit/pull/164) diff --git a/src/Process/CommandLine.php b/src/Process/CommandLine.php index 1a73425e..5d6ce7aa 100644 --- a/src/Process/CommandLine.php +++ b/src/Process/CommandLine.php @@ -59,6 +59,10 @@ public function getOptions(PHPUnitConfig $config): array ]); foreach ($config->getPhpunitOptions() as $phpunitOption) { + if ($this->chunkSize->isChunked() && $phpunitOption->getName() === 'testsuite') { + continue; + } + $options[] = $this->buildPhpunitOptionString($phpunitOption); } diff --git a/tests/Unit/Process/CommandLineTest.php b/tests/Unit/Process/CommandLineTest.php index def47109..e6be9e86 100644 --- a/tests/Unit/Process/CommandLineTest.php +++ b/tests/Unit/Process/CommandLineTest.php @@ -82,8 +82,51 @@ public function testGetOptionsChunkedNotContainsConfiguration(): void $phpunit = $this->prophesize(PHPUnitBinFile::class); $cli = new CommandLine($phpunit->reveal(), $this->mockChunkSize(true)); - $options = $cli->getOptions($config->reveal()); - $this->assertNotContains('--configuration=/path/to/phpunit.xml', $options); + foreach ($cli->getOptions($config->reveal()) as $option) { + $this->assertStringStartsNotWith('--configuration', $option); + } + } + + public function testGetOptionsChunkedNotContainsTestsuite(): void + { + $config = $this->prophesize(PHPUnitConfig::class); + $config->getPhpunitOption('stderr') + ->willReturn(null); + + $config->getFileFullPath() + ->willReturn('/path/to/phpunit.xml'); + + $incompatibleOption = new PHPUnitOption('testsuite'); + $incompatibleOption->setValue('foo'); + $config->getPhpunitOptions() + ->willReturn([$incompatibleOption]); + + $phpunit = $this->prophesize(PHPUnitBinFile::class); + + $cli = new CommandLine($phpunit->reveal(), $this->mockChunkSize(true)); + foreach ($cli->getOptions($config->reveal()) as $option) { + $this->assertStringStartsNotWith('--testsuite', $option); + } + } + + public function testGetOptionsNotChunkedContainsTestsuite(): void + { + $config = $this->prophesize(PHPUnitConfig::class); + $config->getPhpunitOption('stderr') + ->willReturn(null); + + $config->getFileFullPath() + ->willReturn('/path/to/phpunit.xml'); + + $incompatibleOption = new PHPUnitOption('testsuite'); + $incompatibleOption->setValue('foo'); + $config->getPhpunitOptions() + ->willReturn([$incompatibleOption]); + + $phpunit = $this->prophesize(PHPUnitBinFile::class); + + $cli = new CommandLine($phpunit->reveal(), $this->mockChunkSize(false)); + $this->assertContains('--testsuite=foo', $cli->getOptions($config->reveal())); } private function mockChunkSize(bool $enabled): ChunkSize