Skip to content

Commit

Permalink
Also close #5076 for PHPUnit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Oct 12, 2022
1 parent 03e729d commit c529d6b
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .psalm/baseline.xml
Expand Up @@ -652,7 +652,7 @@
<code>hasCacheDirectory</code>
<code>hasCacheResultFile</code>
</DeprecatedMethod>
<MissingThrowsDocblock occurrences="87">
<MissingThrowsDocblock occurrences="88">
<code>backupGlobals</code>
<code>backupStaticProperties</code>
<code>beStrictAboutChangesToGlobalState</code>
Expand Down Expand Up @@ -731,6 +731,7 @@
<code>stopOnWarning</code>
<code>strictCoverage</code>
<code>teamcityLogfile</code>
<code>testSuite</code>
<code>testdoxHtmlFile</code>
<code>testdoxTextFile</code>
<code>testdoxXmlFile</code>
Expand Down
30 changes: 30 additions & 0 deletions src/TextUI/Command/Commands/ListGroupsCommand.php
Expand Up @@ -13,6 +13,7 @@
use function sprintf;
use function str_starts_with;
use PHPUnit\Framework\TestSuite;
use PHPUnit\TextUI\Configuration\Registry;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand Down Expand Up @@ -46,4 +47,33 @@ public function execute(): Result

return Result::from($buffer);
}

private function warnAboutConflictingOptions(): string
{
$buffer = '';

$configuration = Registry::get();

if ($configuration->hasFilter()) {
$buffer .= 'The --filter and --list-groups options cannot be combined, --filter is ignored' . PHP_EOL;
}

if ($configuration->hasGroups()) {
$buffer .= 'The --group and --list-groups options cannot be combined, --group is ignored' . PHP_EOL;
}

if ($configuration->hasExcludeGroups()) {
$buffer .= 'The --exclude-group and --list-groups options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if ($configuration->hasTestSuite()) {
$buffer .= 'The --testsuite and --list-groups options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if (!empty($buffer)) {
$buffer .= PHP_EOL;
}

return $buffer;
}
}
30 changes: 30 additions & 0 deletions src/TextUI/Command/Commands/ListTestSuitesCommand.php
Expand Up @@ -10,6 +10,7 @@
namespace PHPUnit\TextUI\Command;

use function sprintf;
use PHPUnit\TextUI\Configuration\Registry;
use PHPUnit\TextUI\XmlConfiguration\TestSuiteCollection;

/**
Expand Down Expand Up @@ -37,4 +38,33 @@ public function execute(): Result

return Result::from($buffer);
}

private function warnAboutConflictingOptions(): string
{
$buffer = '';

$configuration = Registry::get();

if ($configuration->hasFilter()) {
$buffer .= 'The --filter and --list-suites options cannot be combined, --filter is ignored' . PHP_EOL;
}

if ($configuration->hasGroups()) {
$buffer .= 'The --group and --list-suites options cannot be combined, --group is ignored' . PHP_EOL;
}

if ($configuration->hasExcludeGroups()) {
$buffer .= 'The --exclude-group and --list-suites options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if ($configuration->hasTestSuite()) {
$buffer .= 'The --testsuite and --list-suites options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if (!empty($buffer)) {
$buffer .= PHP_EOL;
}

return $buffer;
}
}
34 changes: 33 additions & 1 deletion src/TextUI/Command/Commands/ListTestsAsTextCommand.php
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Runner\PhptTestCase;
use PHPUnit\TextUI\Configuration\Registry;
use RecursiveIteratorIterator;

/**
Expand All @@ -30,7 +31,9 @@ public function __construct(TestSuite $suite)

public function execute(): Result
{
$buffer = 'Available test(s):' . PHP_EOL;
$buffer = $this->warnAboutConflictingOptions();

$buffer .= 'Available test(s):' . PHP_EOL;

foreach (new RecursiveIteratorIterator($this->suite) as $test) {
if ($test instanceof TestCase) {
Expand All @@ -53,4 +56,33 @@ public function execute(): Result

return Result::from($buffer);
}

private function warnAboutConflictingOptions(): string
{
$buffer = '';

$configuration = Registry::get();

if ($configuration->hasFilter()) {
$buffer .= 'The --filter and --list-tests options cannot be combined, --filter is ignored' . PHP_EOL;
}

if ($configuration->hasGroups()) {
$buffer .= 'The --group and --list-tests options cannot be combined, --group is ignored' . PHP_EOL;
}

if ($configuration->hasExcludeGroups()) {
$buffer .= 'The --exclude-group and --list-tests options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if ($configuration->hasTestSuite()) {
$buffer .= 'The --testsuite and --list-tests options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if (!empty($buffer)) {
$buffer .= PHP_EOL;
}

return $buffer;
}
}
30 changes: 30 additions & 0 deletions src/TextUI/Command/Commands/ListTestsAsXmlCommand.php
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Runner\PhptTestCase;
use PHPUnit\TextUI\Configuration\Registry;
use RecursiveIteratorIterator;
use XMLWriter;

Expand Down Expand Up @@ -101,4 +102,33 @@ public function execute(): Result

return Result::from($buffer);
}

private function warnAboutConflictingOptions(): string
{
$buffer = '';

$configuration = Registry::get();

if ($configuration->hasFilter()) {
$buffer .= 'The --filter and --list-tests-xml options cannot be combined, --filter is ignored' . PHP_EOL;
}

if ($configuration->hasGroups()) {
$buffer .= 'The --group and --list-tests-xml options cannot be combined, --group is ignored' . PHP_EOL;
}

if ($configuration->hasExcludeGroups()) {
$buffer .= 'The --exclude-group and --list-tests-xml options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if ($configuration->hasTestSuite()) {
$buffer .= 'The --testsuite and --list-tests-xml options cannot be combined, --exclude-group is ignored' . PHP_EOL;
}

if (!empty($buffer)) {
$buffer .= PHP_EOL;
}

return $buffer;
}
}

0 comments on commit c529d6b

Please sign in to comment.