Skip to content

Commit 6c16485

Browse files
Refactor
1 parent cc7a121 commit 6c16485

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/TextUI/Application.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,14 @@ private function executeCommandsThatRequireTheTestSuite(Configuration $configura
446446
}
447447

448448
if ($cliConfiguration->listTestFiles()) {
449-
$this->execute(new ListTestFilesCommand($testSuite));
449+
$this->execute(
450+
new ListTestFilesCommand(
451+
$this->filteredTests(
452+
$configuration,
453+
$testSuite,
454+
),
455+
),
456+
);
450457
}
451458
}
452459

src/TextUI/Command/Commands/ListTestFilesCommand.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
*/
1010
namespace PHPUnit\TextUI\Command;
1111

12-
use function array_intersect;
1312
use function array_unique;
13+
use function assert;
1414
use function sprintf;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestSuite;
1716
use PHPUnit\Runner\PhptTestCase;
1817
use PHPUnit\TextUI\Configuration\Registry;
19-
use RecursiveIteratorIterator;
2018
use ReflectionClass;
2119
use ReflectionException;
2220

@@ -25,11 +23,17 @@
2523
*/
2624
final readonly class ListTestFilesCommand implements Command
2725
{
28-
private TestSuite $suite;
26+
/**
27+
* @psalm-var list<TestCase|PhptTestCase>
28+
*/
29+
private array $tests;
2930

30-
public function __construct(TestSuite $suite)
31+
/**
32+
* @psalm-param list<TestCase|PhptTestCase> $tests
33+
*/
34+
public function __construct(array $tests)
3135
{
32-
$this->suite = $suite;
36+
$this->tests = $tests;
3337
}
3438

3539
/**
@@ -43,30 +47,18 @@ public function execute(): Result
4347

4448
$results = [];
4549

46-
foreach (new RecursiveIteratorIterator($this->suite) as $test) {
50+
foreach ($this->tests as $test) {
4751
if ($test instanceof TestCase) {
4852
$name = (new ReflectionClass($test))->getFileName();
4953

50-
// @codeCoverageIgnoreStart
51-
if ($name === false) {
52-
continue;
53-
}
54-
// @codeCoverageIgnoreEnd
54+
assert($name !== false);
5555

56-
if ($configuration->hasGroups() && empty(array_intersect($configuration->groups(), $test->groups()))) {
57-
continue;
58-
}
56+
$results[] = $name;
5957

60-
if ($configuration->hasExcludeGroups() && !empty(array_intersect($configuration->excludeGroups(), $test->groups()))) {
61-
continue;
62-
}
63-
} elseif ($test instanceof PhptTestCase) {
64-
$name = $test->getName();
65-
} else {
6658
continue;
6759
}
6860

69-
$results[] = $name;
61+
$results[] = $test->getName();
7062
}
7163

7264
foreach (array_unique($results) as $result) {

0 commit comments

Comments
 (0)