Skip to content

Commit a84ab3b

Browse files
Merge branch '8.5' into 9.5
2 parents 2132be2 + d420cab commit a84ab3b

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

ChangeLog-8.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 8.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [8.5.31] - 2022-MM-DD
6+
7+
### Fixed
8+
9+
* [#5076](https://github.com/sebastianbergmann/phpunit/issues/5076): Test Runner does not warn about conflicting options
10+
511
## [8.5.30] - 2022-09-25
612

713
### Changed
@@ -250,6 +256,7 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil
250256
* [#3967](https://github.com/sebastianbergmann/phpunit/issues/3967): Cannot double interface that extends interface that extends `\Throwable`
251257
* [#3968](https://github.com/sebastianbergmann/phpunit/pull/3968): Test class run in a separate PHP process are passing when `exit` called inside
252258

259+
[8.5.31]: https://github.com/sebastianbergmann/phpunit/compare/8.5.30...8.5
253260
[8.5.30]: https://github.com/sebastianbergmann/phpunit/compare/8.5.29...8.5.30
254261
[8.5.29]: https://github.com/sebastianbergmann/phpunit/compare/8.5.28...8.5.29
255262
[8.5.28]: https://github.com/sebastianbergmann/phpunit/compare/8.5.27...8.5.28

ChangeLog-9.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 9.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [9.5.26] - 2022-MM-DD
6+
7+
### Fixed
8+
9+
* [#5076](https://github.com/sebastianbergmann/phpunit/issues/5076): Test Runner does not warn about conflicting options
10+
511
## [9.5.25] - 2022-09-25
612

713
### Added
@@ -200,6 +206,7 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil
200206

201207
* [#4535](https://github.com/sebastianbergmann/phpunit/issues/4535): `getMockFromWsdl()` does not handle methods that do not have parameters correctly
202208

209+
[9.5.26]: https://github.com/sebastianbergmann/phpunit/compare/9.5.25...9.5
203210
[9.5.25]: https://github.com/sebastianbergmann/phpunit/compare/9.5.24...9.5.25
204211
[9.5.24]: https://github.com/sebastianbergmann/phpunit/compare/9.5.23...9.5.24
205212
[9.5.23]: https://github.com/sebastianbergmann/phpunit/compare/9.5.22...9.5.23

src/TextUI/Command.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ private function handleListGroups(TestSuite $suite, bool $exit): int
641641
{
642642
$this->printVersionString();
643643

644+
$this->warnAboutConflictingOptions(
645+
'listGroups',
646+
[
647+
'filter',
648+
'groups',
649+
'excludeGroups',
650+
'testsuite',
651+
]
652+
);
653+
644654
print 'Available test group(s):' . PHP_EOL;
645655

646656
$groups = $suite->getGroups();
@@ -672,6 +682,16 @@ private function handleListSuites(bool $exit): int
672682
{
673683
$this->printVersionString();
674684

685+
$this->warnAboutConflictingOptions(
686+
'listSuites',
687+
[
688+
'filter',
689+
'groups',
690+
'excludeGroups',
691+
'testsuite',
692+
]
693+
);
694+
675695
print 'Available test suite(s):' . PHP_EOL;
676696

677697
foreach ($this->arguments['configurationObject']->testSuite() as $testSuite) {
@@ -695,6 +715,16 @@ private function handleListTests(TestSuite $suite, bool $exit): int
695715
{
696716
$this->printVersionString();
697717

718+
$this->warnAboutConflictingOptions(
719+
'listTests',
720+
[
721+
'filter',
722+
'groups',
723+
'excludeGroups',
724+
'testsuite',
725+
]
726+
);
727+
698728
$renderer = new TextTestListRenderer;
699729

700730
print $renderer->render($suite);
@@ -713,6 +743,16 @@ private function handleListTestsXml(TestSuite $suite, string $target, bool $exit
713743
{
714744
$this->printVersionString();
715745

746+
$this->warnAboutConflictingOptions(
747+
'listTestsXml',
748+
[
749+
'filter',
750+
'groups',
751+
'excludeGroups',
752+
'testsuite',
753+
]
754+
);
755+
716756
$renderer = new XmlTestListRenderer;
717757

718758
file_put_contents($target, $renderer->render($suite));
@@ -905,4 +945,62 @@ private function configurationFileInDirectory(string $directory): ?string
905945

906946
return null;
907947
}
948+
949+
/**
950+
* @psalm-param "listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite" $key
951+
* @psalm-param list<"listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite"> $keys
952+
*/
953+
private function warnAboutConflictingOptions(string $key, array $keys): void
954+
{
955+
$warningPrinted = false;
956+
957+
foreach ($keys as $_key) {
958+
if (!empty($this->arguments[$_key])) {
959+
printf(
960+
'The %s and %s options cannot be combined, %s is ignored' . PHP_EOL,
961+
$this->mapKeyToOptionForWarning($_key),
962+
$this->mapKeyToOptionForWarning($key),
963+
$this->mapKeyToOptionForWarning($_key)
964+
);
965+
966+
$warningPrinted = true;
967+
}
968+
}
969+
970+
if ($warningPrinted) {
971+
print PHP_EOL;
972+
}
973+
}
974+
975+
/**
976+
* @psalm-param "listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite" $key
977+
*/
978+
private function mapKeyToOptionForWarning(string $key): string
979+
{
980+
switch ($key) {
981+
case 'listGroups':
982+
return '--list-groups';
983+
984+
case 'listSuites':
985+
return '--list-suites';
986+
987+
case 'listTests':
988+
return '--list-tests';
989+
990+
case 'listTestsXml':
991+
return '--list-tests-xml';
992+
993+
case 'filter':
994+
return '--filter';
995+
996+
case 'groups':
997+
return '--group';
998+
999+
case 'excludeGroups':
1000+
return '--exclude-group';
1001+
1002+
case 'testsuite':
1003+
return '--testsuite';
1004+
}
1005+
}
9081006
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
phpunit --list-tests --filter testAdd#0 ../../_files/DataProviderTest.php
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--list-tests';
8+
$_SERVER['argv'][] = '--filter';
9+
$_SERVER['argv'][] = 'testAdd#0';
10+
$_SERVER['argv'][] = __DIR__ . '/../../_files/DataProviderTest.php';
11+
12+
require_once __DIR__ . '/../../bootstrap.php';
13+
PHPUnit\TextUI\Command::main();
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
The --filter and --list-tests options cannot be combined, --filter is ignored
18+
19+
Available test(s):
20+
- PHPUnit\TestFixture\DataProviderTest::testAdd#0
21+
- PHPUnit\TestFixture\DataProviderTest::testAdd#1
22+
- PHPUnit\TestFixture\DataProviderTest::testAdd#2
23+
- PHPUnit\TestFixture\DataProviderTest::testAdd#3

0 commit comments

Comments
 (0)