Skip to content

Commit d420cab

Browse files
Closes #5076
1 parent 4f50e83 commit d420cab

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-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

src/TextUI/Command.php

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

1238+
$this->warnAboutConflictingOptions(
1239+
'listGroups',
1240+
[
1241+
'filter',
1242+
'groups',
1243+
'excludeGroups',
1244+
'testsuite',
1245+
]
1246+
);
1247+
12381248
print 'Available test group(s):' . PHP_EOL;
12391249

12401250
$groups = $suite->getGroups();
@@ -1261,6 +1271,16 @@ private function handleListSuites(bool $exit): int
12611271
{
12621272
$this->printVersionString();
12631273

1274+
$this->warnAboutConflictingOptions(
1275+
'listSuites',
1276+
[
1277+
'filter',
1278+
'groups',
1279+
'excludeGroups',
1280+
'testsuite',
1281+
]
1282+
);
1283+
12641284
print 'Available test suite(s):' . PHP_EOL;
12651285

12661286
$configuration = Configuration::getInstance(
@@ -1288,6 +1308,16 @@ private function handleListTests(TestSuite $suite, bool $exit): int
12881308
{
12891309
$this->printVersionString();
12901310

1311+
$this->warnAboutConflictingOptions(
1312+
'listTests',
1313+
[
1314+
'filter',
1315+
'groups',
1316+
'excludeGroups',
1317+
'testsuite',
1318+
]
1319+
);
1320+
12911321
$renderer = new TextTestListRenderer;
12921322

12931323
print $renderer->render($suite);
@@ -1306,6 +1336,16 @@ private function handleListTestsXml(TestSuite $suite, string $target, bool $exit
13061336
{
13071337
$this->printVersionString();
13081338

1339+
$this->warnAboutConflictingOptions(
1340+
'listTestsXml',
1341+
[
1342+
'filter',
1343+
'groups',
1344+
'excludeGroups',
1345+
'testsuite',
1346+
]
1347+
);
1348+
13091349
$renderer = new XmlTestListRenderer;
13101350

13111351
file_put_contents($target, $renderer->render($suite));
@@ -1373,4 +1413,62 @@ private function handleOrderByOption(string $value): void
13731413
}
13741414
}
13751415
}
1416+
1417+
/**
1418+
* @psalm-param "listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite" $key
1419+
* @psalm-param list<"listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite"> $keys
1420+
*/
1421+
private function warnAboutConflictingOptions(string $key, array $keys): void
1422+
{
1423+
$warningPrinted = false;
1424+
1425+
foreach ($keys as $_key) {
1426+
if (!empty($this->arguments[$_key])) {
1427+
printf(
1428+
'The %s and %s options cannot be combined, %s is ignored' . PHP_EOL,
1429+
$this->mapKeyToOptionForWarning($_key),
1430+
$this->mapKeyToOptionForWarning($key),
1431+
$this->mapKeyToOptionForWarning($_key)
1432+
);
1433+
1434+
$warningPrinted = true;
1435+
}
1436+
}
1437+
1438+
if ($warningPrinted) {
1439+
print PHP_EOL;
1440+
}
1441+
}
1442+
1443+
/**
1444+
* @psalm-param "listGroups"|"listSuites"|"listTests"|"listTestsXml"|"filter"|"groups"|"excludeGroups"|"testsuite" $key
1445+
*/
1446+
private function mapKeyToOptionForWarning(string $key): string
1447+
{
1448+
switch ($key) {
1449+
case 'listGroups':
1450+
return '--list-groups';
1451+
1452+
case 'listSuites':
1453+
return '--list-suites';
1454+
1455+
case 'listTests':
1456+
return '--list-tests';
1457+
1458+
case 'listTestsXml':
1459+
return '--list-tests-xml';
1460+
1461+
case 'filter':
1462+
return '--filter';
1463+
1464+
case 'groups':
1465+
return '--group';
1466+
1467+
case 'excludeGroups':
1468+
return '--exclude-group';
1469+
1470+
case 'testsuite':
1471+
return '--testsuite';
1472+
}
1473+
}
13761474
}
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)