-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TextUI\Command; | ||
|
||
use function array_intersect; | ||
use function array_unique; | ||
use function sprintf; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit\Framework\TestSuite; | ||
use PHPUnit\Runner\PhptTestCase; | ||
use PHPUnit\TextUI\Configuration\Registry; | ||
use RecursiveIteratorIterator; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
|
||
/** | ||
* @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final readonly class ListTestFilesCommand implements Command | ||
{ | ||
private readonly TestSuite $suite; | ||
|
||
public function __construct(TestSuite $suite) | ||
{ | ||
$this->suite = $suite; | ||
} | ||
|
||
/** | ||
* @throws ReflectionException | ||
*/ | ||
public function execute(): Result | ||
{ | ||
$configuration = Registry::get(); | ||
|
||
$buffer = 'Available test files:' . PHP_EOL; | ||
|
||
$results = []; | ||
|
||
foreach (new RecursiveIteratorIterator($this->suite) as $test) { | ||
if ($test instanceof TestCase) { | ||
$name = (new ReflectionClass($test))->getFileName(); | ||
|
||
// @codeCoverageIgnoreStart | ||
if ($name === false) { | ||
continue; | ||
} | ||
// @codeCoverageIgnoreEnd | ||
|
||
if ($configuration->hasGroups() && empty(array_intersect($configuration->groups(), $test->groups()))) { | ||
continue; | ||
} | ||
|
||
if ($configuration->hasExcludeGroups() && !empty(array_intersect($configuration->excludeGroups(), $test->groups()))) { | ||
continue; | ||
} | ||
} elseif ($test instanceof PhptTestCase) { | ||
$name = $test->getName(); | ||
} else { | ||
continue; | ||
} | ||
|
||
$results[] = $name; | ||
} | ||
|
||
foreach (array_unique($results) as $result) { | ||
$buffer .= sprintf( | ||
' - %s' . PHP_EOL, | ||
$result, | ||
); | ||
} | ||
|
||
return Result::from($buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/end-to-end/cli/list-file-tests/list-phpt-test-files.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
phpunit --list-test-files list-phpt-test-files.phpt | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--list-test-files'; | ||
$_SERVER['argv'][] = __DIR__.'/list-phpt-test-files.phpt'; | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Available test files: | ||
- %send-to-end%slist-phpt-test-files.phpt |
16 changes: 16 additions & 0 deletions
16
tests/end-to-end/cli/list-file-tests/list-test-files-exclude-group.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
phpunit --list-test-files --exclude-group group ../../../_files/Metadata/Annotation/tests/GroupTest.php | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--list-test-files'; | ||
$_SERVER['argv'][] = '--exclude-group'; | ||
$_SERVER['argv'][] = 'group'; | ||
$_SERVER['argv'][] = __DIR__.'/../../../_files/Metadata/Annotation/tests/GroupTest.php'; | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Available test files: |
17 changes: 17 additions & 0 deletions
17
tests/end-to-end/cli/list-file-tests/list-test-files-group.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
phpunit --list-test-files --group group ../../../_files/Metadata/Annotation/tests/ | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--list-test-files'; | ||
$_SERVER['argv'][] = '--group'; | ||
$_SERVER['argv'][] = 'group'; | ||
$_SERVER['argv'][] = __DIR__.'/../../../_files/Metadata/Annotation/tests/'; | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Available test files: | ||
- %Annotation%sGroupTest.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
phpunit --list-test-files --configuration ../../../_files/basic/configuration.basic.xml | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--list-test-files'; | ||
$_SERVER['argv'][] = '--configuration'; | ||
$_SERVER['argv'][] = __DIR__.'/../../_files/basic/configuration.basic.xml'; | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Available test files: | ||
- %send-to-end%sSetUpBeforeClassTest.php | ||
- %send-to-end%sSetUpTest.php | ||
- %send-to-end%sStatusTest.php | ||
- %send-to-end%sTearDownAfterClassTest.php |