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/ChangeLog-9.5.md b/ChangeLog-9.5.md index 0a01f03f01d..038936fb343 100644 --- a/ChangeLog-9.5.md +++ b/ChangeLog-9.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 9.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [9.5.26] - 2022-MM-DD + +### Fixed + +* [#5076](https://github.com/sebastianbergmann/phpunit/issues/5076): Test Runner does not warn about conflicting options + ## [9.5.25] - 2022-09-25 ### Added @@ -200,6 +206,7 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil * [#4535](https://github.com/sebastianbergmann/phpunit/issues/4535): `getMockFromWsdl()` does not handle methods that do not have parameters correctly +[9.5.26]: https://github.com/sebastianbergmann/phpunit/compare/9.5.25...9.5 [9.5.25]: https://github.com/sebastianbergmann/phpunit/compare/9.5.24...9.5.25 [9.5.24]: https://github.com/sebastianbergmann/phpunit/compare/9.5.23...9.5.24 [9.5.23]: https://github.com/sebastianbergmann/phpunit/compare/9.5.22...9.5.23 diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 8097bbf3616..3276c0951ce 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -641,6 +641,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(); @@ -672,6 +682,16 @@ private function handleListSuites(bool $exit): int { $this->printVersionString(); + $this->warnAboutConflictingOptions( + 'listSuites', + [ + 'filter', + 'groups', + 'excludeGroups', + 'testsuite', + ] + ); + print 'Available test suite(s):' . PHP_EOL; foreach ($this->arguments['configurationObject']->testSuite() as $testSuite) { @@ -695,6 +715,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); @@ -713,6 +743,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)); @@ -905,4 +945,62 @@ private function configurationFileInDirectory(string $directory): ?string return null; } + + /** + * @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-- +