Skip to content

Commit

Permalink
Merge branch '8.5' into 9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 12, 2022
2 parents 2132be2 + d420cab commit a84ab3b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-8.5.md
Original file line number Diff line number Diff line change
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
7 changes: 7 additions & 0 deletions ChangeLog-9.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
98 changes: 98 additions & 0 deletions src/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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';
}
}
}
23 changes: 23 additions & 0 deletions tests/end-to-end/cli/list-tests-dataprovider-filter.phpt
Original file line number Diff line number Diff line change
@@ -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 a84ab3b

Please sign in to comment.