diff --git a/ChangeLog-8.5.md b/ChangeLog-8.5.md index eb6460f65c4..4ddc53ec95e 100644 --- a/ChangeLog-8.5.md +++ b/ChangeLog-8.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 8.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [8.5.31] - 2022-MM-DD + +### Fixed + +* [#5076](https://github.com/sebastianbergmann/phpunit/issues/5076): Test Runner does not warn about conflicting options + ## [8.5.30] - 2022-09-25 ### Changed @@ -250,6 +256,7 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil * [#3967](https://github.com/sebastianbergmann/phpunit/issues/3967): Cannot double interface that extends interface that extends `\Throwable` * [#3968](https://github.com/sebastianbergmann/phpunit/pull/3968): Test class run in a separate PHP process are passing when `exit` called inside +[8.5.31]: https://github.com/sebastianbergmann/phpunit/compare/8.5.30...8.5 [8.5.30]: https://github.com/sebastianbergmann/phpunit/compare/8.5.29...8.5.30 [8.5.29]: https://github.com/sebastianbergmann/phpunit/compare/8.5.28...8.5.29 [8.5.28]: https://github.com/sebastianbergmann/phpunit/compare/8.5.27...8.5.28 diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index f8ea1af3050..4b8e5367c86 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -1235,6 +1235,16 @@ private function handleListGroups(TestSuite $suite, bool $exit): int { $this->printVersionString(); + $this->warnAboutConflictingOptions( + 'listGroups', + [ + 'filter', + 'groups', + 'excludeGroups', + 'testsuite', + ] + ); + print 'Available test group(s):' . PHP_EOL; $groups = $suite->getGroups(); @@ -1261,6 +1271,16 @@ private function handleListSuites(bool $exit): int { $this->printVersionString(); + $this->warnAboutConflictingOptions( + 'listSuites', + [ + 'filter', + 'groups', + 'excludeGroups', + 'testsuite', + ] + ); + print 'Available test suite(s):' . PHP_EOL; $configuration = Configuration::getInstance( @@ -1288,6 +1308,16 @@ private function handleListTests(TestSuite $suite, bool $exit): int { $this->printVersionString(); + $this->warnAboutConflictingOptions( + 'listTests', + [ + 'filter', + 'groups', + 'excludeGroups', + 'testsuite', + ] + ); + $renderer = new TextTestListRenderer; print $renderer->render($suite); @@ -1306,6 +1336,16 @@ private function handleListTestsXml(TestSuite $suite, string $target, bool $exit { $this->printVersionString(); + $this->warnAboutConflictingOptions( + 'listTestsXml', + [ + 'filter', + 'groups', + 'excludeGroups', + 'testsuite', + ] + ); + $renderer = new XmlTestListRenderer; file_put_contents($target, $renderer->render($suite)); @@ -1373,4 +1413,62 @@ private function handleOrderByOption(string $value): void } } } + + /** + * @psalm-param "listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite" $key + * @psalm-param list<"listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite"> $keys + */ + private function warnAboutConflictingOptions(string $key, array $keys): void + { + $warningPrinted = false; + + foreach ($keys as $_key) { + if (!empty($this->arguments[$_key])) { + printf( + 'The %s and %s options cannot be combined, %s is ignored' . PHP_EOL, + $this->mapKeyToOptionForWarning($_key), + $this->mapKeyToOptionForWarning($key), + $this->mapKeyToOptionForWarning($_key) + ); + + $warningPrinted = true; + } + } + + if ($warningPrinted) { + print PHP_EOL; + } + } + + /** + * @psalm-param "listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite" $key + */ + private function mapKeyToOptionForWarning(string $key): string + { + switch ($key) { + case 'listGroups': + return '--list-groups'; + + case 'listSuites': + return '--list-suites'; + + case 'listTests': + return '--list-tests'; + + case 'listTestsXml': + return '--list-tests-xml'; + + case 'filter': + return '--filter'; + + case 'groups': + return '--group'; + + case 'excludeGroups': + return '--exclude-group'; + + case 'testsuite': + return '--testsuite'; + } + } } diff --git a/tests/end-to-end/cli/list-tests-dataprovider-filter.phpt b/tests/end-to-end/cli/list-tests-dataprovider-filter.phpt new file mode 100644 index 00000000000..0476778e1a5 --- /dev/null +++ b/tests/end-to-end/cli/list-tests-dataprovider-filter.phpt @@ -0,0 +1,23 @@ +--TEST-- +phpunit --list-tests --filter testAdd#0 ../../_files/DataProviderTest.php +--FILE-- +