diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index 034e726e784..145c0cd9a61 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -652,7 +652,7 @@ hasCacheDirectory hasCacheResultFile - + backupGlobals backupStaticProperties beStrictAboutChangesToGlobalState @@ -731,6 +731,7 @@ stopOnWarning strictCoverage teamcityLogfile + testSuite testdoxHtmlFile testdoxTextFile testdoxXmlFile diff --git a/src/TextUI/Command/Commands/ListGroupsCommand.php b/src/TextUI/Command/Commands/ListGroupsCommand.php index e0a9ee87b8a..f292e73da80 100644 --- a/src/TextUI/Command/Commands/ListGroupsCommand.php +++ b/src/TextUI/Command/Commands/ListGroupsCommand.php @@ -13,6 +13,7 @@ use function sprintf; use function str_starts_with; use PHPUnit\Framework\TestSuite; +use PHPUnit\TextUI\Configuration\Registry; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit @@ -46,4 +47,33 @@ public function execute(): Result return Result::from($buffer); } + + private function warnAboutConflictingOptions(): string + { + $buffer = ''; + + $configuration = Registry::get(); + + if ($configuration->hasFilter()) { + $buffer .= 'The --filter and --list-groups options cannot be combined, --filter is ignored' . PHP_EOL; + } + + if ($configuration->hasGroups()) { + $buffer .= 'The --group and --list-groups options cannot be combined, --group is ignored' . PHP_EOL; + } + + if ($configuration->hasExcludeGroups()) { + $buffer .= 'The --exclude-group and --list-groups options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if ($configuration->hasTestSuite()) { + $buffer .= 'The --testsuite and --list-groups options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if (!empty($buffer)) { + $buffer .= PHP_EOL; + } + + return $buffer; + } } diff --git a/src/TextUI/Command/Commands/ListTestSuitesCommand.php b/src/TextUI/Command/Commands/ListTestSuitesCommand.php index 51df534a254..f8fe9f5029d 100644 --- a/src/TextUI/Command/Commands/ListTestSuitesCommand.php +++ b/src/TextUI/Command/Commands/ListTestSuitesCommand.php @@ -10,6 +10,7 @@ namespace PHPUnit\TextUI\Command; use function sprintf; +use PHPUnit\TextUI\Configuration\Registry; use PHPUnit\TextUI\XmlConfiguration\TestSuiteCollection; /** @@ -37,4 +38,33 @@ public function execute(): Result return Result::from($buffer); } + + private function warnAboutConflictingOptions(): string + { + $buffer = ''; + + $configuration = Registry::get(); + + if ($configuration->hasFilter()) { + $buffer .= 'The --filter and --list-suites options cannot be combined, --filter is ignored' . PHP_EOL; + } + + if ($configuration->hasGroups()) { + $buffer .= 'The --group and --list-suites options cannot be combined, --group is ignored' . PHP_EOL; + } + + if ($configuration->hasExcludeGroups()) { + $buffer .= 'The --exclude-group and --list-suites options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if ($configuration->hasTestSuite()) { + $buffer .= 'The --testsuite and --list-suites options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if (!empty($buffer)) { + $buffer .= PHP_EOL; + } + + return $buffer; + } } diff --git a/src/TextUI/Command/Commands/ListTestsAsTextCommand.php b/src/TextUI/Command/Commands/ListTestsAsTextCommand.php index da3a502522b..ccb64662213 100644 --- a/src/TextUI/Command/Commands/ListTestsAsTextCommand.php +++ b/src/TextUI/Command/Commands/ListTestsAsTextCommand.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestSuite; use PHPUnit\Runner\PhptTestCase; +use PHPUnit\TextUI\Configuration\Registry; use RecursiveIteratorIterator; /** @@ -30,7 +31,9 @@ public function __construct(TestSuite $suite) public function execute(): Result { - $buffer = 'Available test(s):' . PHP_EOL; + $buffer = $this->warnAboutConflictingOptions(); + + $buffer .= 'Available test(s):' . PHP_EOL; foreach (new RecursiveIteratorIterator($this->suite) as $test) { if ($test instanceof TestCase) { @@ -53,4 +56,33 @@ public function execute(): Result return Result::from($buffer); } + + private function warnAboutConflictingOptions(): string + { + $buffer = ''; + + $configuration = Registry::get(); + + if ($configuration->hasFilter()) { + $buffer .= 'The --filter and --list-tests options cannot be combined, --filter is ignored' . PHP_EOL; + } + + if ($configuration->hasGroups()) { + $buffer .= 'The --group and --list-tests options cannot be combined, --group is ignored' . PHP_EOL; + } + + if ($configuration->hasExcludeGroups()) { + $buffer .= 'The --exclude-group and --list-tests options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if ($configuration->hasTestSuite()) { + $buffer .= 'The --testsuite and --list-tests options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if (!empty($buffer)) { + $buffer .= PHP_EOL; + } + + return $buffer; + } } diff --git a/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php b/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php index aac95867e18..c4d4cdf5da0 100644 --- a/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php +++ b/src/TextUI/Command/Commands/ListTestsAsXmlCommand.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestSuite; use PHPUnit\Runner\PhptTestCase; +use PHPUnit\TextUI\Configuration\Registry; use RecursiveIteratorIterator; use XMLWriter; @@ -101,4 +102,33 @@ public function execute(): Result return Result::from($buffer); } + + private function warnAboutConflictingOptions(): string + { + $buffer = ''; + + $configuration = Registry::get(); + + if ($configuration->hasFilter()) { + $buffer .= 'The --filter and --list-tests-xml options cannot be combined, --filter is ignored' . PHP_EOL; + } + + if ($configuration->hasGroups()) { + $buffer .= 'The --group and --list-tests-xml options cannot be combined, --group is ignored' . PHP_EOL; + } + + if ($configuration->hasExcludeGroups()) { + $buffer .= 'The --exclude-group and --list-tests-xml options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if ($configuration->hasTestSuite()) { + $buffer .= 'The --testsuite and --list-tests-xml options cannot be combined, --exclude-group is ignored' . PHP_EOL; + } + + if (!empty($buffer)) { + $buffer .= PHP_EOL; + } + + return $buffer; + } }