diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 5c9d86c9..820daf81 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -19,6 +19,7 @@
getOption('testsuite')]]>
getOption('exclude-testsuite')]]>
getOption('sort')]]>
+ getOption('test-suffix')]]>
diff --git a/src/Command/ParallelCommand.php b/src/Command/ParallelCommand.php
index c4568773..390aac19 100644
--- a/src/Command/ParallelCommand.php
+++ b/src/Command/ParallelCommand.php
@@ -36,6 +36,7 @@ protected function configure(): void
$this->addOption('pass-through', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Inject options to be passed directly to the underlying PHPUnit processes');
$this->addOption('testsuite', null, InputOption::VALUE_REQUIRED, 'Only run tests from the specified test suite');
$this->addOption('exclude-testsuite', null, InputOption::VALUE_REQUIRED, 'Exclude test suite from running');
+ $this->addOption('test-suffix', null, InputOption::VALUE_REQUIRED, 'Only run tests from the specified suffix');
$this->addOption('sort', null, InputOption::VALUE_REQUIRED, 'Choose in which order to execute the test classes (values: "random" only for now)');
}
diff --git a/src/Configuration/DependencyInjection/ParallelContainerDefinition.php b/src/Configuration/DependencyInjection/ParallelContainerDefinition.php
index f256160f..6971f4bb 100644
--- a/src/Configuration/DependencyInjection/ParallelContainerDefinition.php
+++ b/src/Configuration/DependencyInjection/ParallelContainerDefinition.php
@@ -141,7 +141,8 @@ private function configureServices(ContainerBuilder $container): void
$container->autowire(Filter::class)
->setArgument('$testSuiteFilter', '%paraunit.testsuite%')
->setArgument('$stringFilter', '%paraunit.string_filter%')
- ->setArgument('$excludeTestSuiteFilter', '%paraunit.exclude_testsuite%');
+ ->setArgument('$excludeTestSuiteFilter', '%paraunit.exclude_testsuite%')
+ ->setArgument('$testSuffix', '%paraunit.test_suffix%');
$container->autowire(RetryParser::class)
->setArgument('$maxRetryCount', '%paraunit.max_retry_count%');
diff --git a/src/Configuration/ParallelConfiguration.php b/src/Configuration/ParallelConfiguration.php
index b5457e8d..61c7706c 100644
--- a/src/Configuration/ParallelConfiguration.php
+++ b/src/Configuration/ParallelConfiguration.php
@@ -79,6 +79,7 @@ protected function loadCommandLineOptions(ContainerBuilder $containerBuilder, In
$containerBuilder->setParameter('paraunit.pass_through', $input->getOption('pass-through'));
$containerBuilder->setParameter('paraunit.sort_order', $input->getOption('sort'));
$containerBuilder->setParameter('paraunit.exclude_testsuite', $input->getOption('exclude-testsuite'));
+ $containerBuilder->setParameter('paraunit.test_suffix', $input->getOption('test-suffix'));
if ($input->getOption('debug')) {
$this->enableDebugMode($containerBuilder);
diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php
index 13d0c904..a207d7f1 100644
--- a/src/Filter/Filter.php
+++ b/src/Filter/Filter.php
@@ -20,7 +20,8 @@ public function __construct(
private readonly PHPUnitConfig $configFile,
private readonly ?string $testSuiteFilter = null,
private readonly ?string $stringFilter = null,
- private readonly ?string $excludeTestSuiteFilter = null
+ private readonly ?string $excludeTestSuiteFilter = null,
+ private readonly ?string $testSuffix = null
) {
/** @psalm-suppress InternalClass */
$this->xmlLoader = new Loader();
@@ -64,7 +65,7 @@ public function filterTestFiles(): array
}
}
- return $this->filterByString($aggregatedFiles, $this->stringFilter);
+ return $this->filterByString($aggregatedFiles, $this->stringFilter, $this->testSuffix);
}
private function testSuitePassFilter(\DOMElement $testSuiteNode, string $testSuiteFilter = null): bool
@@ -175,12 +176,16 @@ private function getDOMNodeAttribute(
*
* @return string[]
*/
- private function filterByString(array $aggregatedFiles, ?string $stringFilter): array
+ private function filterByString(array $aggregatedFiles, ?string $stringFilter, ?string $suffix): array
{
if ($stringFilter !== null) {
$aggregatedFiles = array_filter($aggregatedFiles, fn($value): bool => stripos($value, $stringFilter) !== false);
}
+ if ($suffix !== null) {
+ $aggregatedFiles = array_filter($aggregatedFiles, fn($value): bool => str_ends_with($value, (string) $this->testSuffix));
+ }
+
return array_values($aggregatedFiles);
}
diff --git a/tests/Functional/Configuration/PassThroughTest.php b/tests/Functional/Configuration/PassThroughTest.php
index a522c0ec..64da331c 100644
--- a/tests/Functional/Configuration/PassThroughTest.php
+++ b/tests/Functional/Configuration/PassThroughTest.php
@@ -186,7 +186,6 @@ private function getPossibleFutureOptions(): array
{
return [
'--exclude-filter',
- '--test-suffix',
'--columns',
'--display-incomplete',
'--display-skipped',
diff --git a/tests/Functional/Filter/SuffixFilterTest.php b/tests/Functional/Filter/SuffixFilterTest.php
new file mode 100644
index 00000000..e0db0a48
--- /dev/null
+++ b/tests/Functional/Filter/SuffixFilterTest.php
@@ -0,0 +1,33 @@
+setOption('configuration', $this->getStubPath() . DIRECTORY_SEPARATOR . 'phpunit_with_2_testsuites.xml');
+ $this->setOption('test-suffix', 'GreenTestStub.php');
+
+ parent::setup();
+ }
+
+ public function testFilterTestBySuffixFiles(): void
+ {
+ /** @var Filter $filter */
+ $filter = $this->getService(Filter::class);
+
+ $files = $filter->filterTestFiles();
+
+ $this->assertCount(1, $files);
+
+ $fileExploded = explode('/', $files[0]);
+
+ $this->assertSame('ThreeGreenTestStub.php', end($fileExploded));
+ }
+}
diff --git a/tests/Unit/Configuration/CoverageConfigurationTest.php b/tests/Unit/Configuration/CoverageConfigurationTest.php
index 5382cec2..9608911d 100644
--- a/tests/Unit/Configuration/CoverageConfigurationTest.php
+++ b/tests/Unit/Configuration/CoverageConfigurationTest.php
@@ -138,6 +138,7 @@ public function testBuildContainerWithCoverageSettings(string $inputOption, stri
'pass-through',
'sort',
'exclude-testsuite',
+ 'test-suffix',
];
foreach ($options as $optionName) {
@@ -207,6 +208,7 @@ public function testBuildContainerWithColoredTextToConsoleCoverage(): void
'pass-through',
'sort',
'exclude-testsuite',
+ 'test-suffix',
];
foreach ($options as $optionName) {