Skip to content

Commit

Permalink
Closes #5076
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 12, 2022
1 parent 4f50e83 commit d420cab
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-8.5.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
98 changes: 98 additions & 0 deletions src/TextUI/Command.php
Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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';
}
}
}
23 changes: 23 additions & 0 deletions 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--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--list-tests';
$_SERVER['argv'][] = '--filter';
$_SERVER['argv'][] = 'testAdd#0';
$_SERVER['argv'][] = __DIR__ . '/../../_files/DataProviderTest.php';

require_once __DIR__ . '/../../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

The --filter and --list-tests options cannot be combined, --filter is ignored

Available test(s):
- PHPUnit\TestFixture\DataProviderTest::testAdd#0
- PHPUnit\TestFixture\DataProviderTest::testAdd#1
- PHPUnit\TestFixture\DataProviderTest::testAdd#2
- PHPUnit\TestFixture\DataProviderTest::testAdd#3

0 comments on commit d420cab

Please sign in to comment.