function PhpUnitTestDiscovery::getTestListLimitedToDirectory
Returns a list of tests from a TestSuite object limited to a directory.
Parameters
\PHPUnit\Framework\TestSuite $phpUnitTestSuite: The TestSuite object returned by PHPUnit test discovery.
string|null $extension: The name of an extension to limit discovery to; e.g., 'node'.
list<string> $testSuites: An array of PHPUnit test suites to filter the discovery for.
Return value
array<string<array<class-string, array{name: class-string, description: string, group: string|int, groups: list<string|int>, type: string, file: string, tests_count: positive-int}>>> An array of test groups keyed by the group name. Each test group is an array of test class information arrays as returned by ::getTestClassInfo(), keyed by test class. If a test class belongs to multiple groups, it will appear under all group keys it belongs to.
1 call to PhpUnitTestDiscovery::getTestListLimitedToDirectory()
- PhpUnitTestDiscovery::getTestClasses in core/
lib/ Drupal/ Core/ Test/ PhpUnitTestDiscovery.php - Discovers available tests.
File
-
core/
lib/ Drupal/ Core/ Test/ PhpUnitTestDiscovery.php, line 216
Class
- PhpUnitTestDiscovery
- Discovers available tests using the PHPUnit API.
Namespace
Drupal\Core\TestCode
private function getTestListLimitedToDirectory(TestSuite $phpUnitTestSuite, ?string $extension, array $testSuites) : array {
$list = [];
// In this case, PHPUnit found a single test class to run tests for.
if ($phpUnitTestSuite->isForTestClass()) {
if ($extension !== NULL && !str_starts_with($phpUnitTestSuite->name(), "Drupal\\Tests\\{$extension}\\")) {
return [];
}
// Take the test suite name from the class namespace.
$testSuite = 'PHPUnit-' . TestDiscovery::getPhpunitTestSuite($phpUnitTestSuite->name());
if (!empty($testSuites) && !in_array($testSuite, $testSuites, TRUE)) {
return [];
}
$item = $this->getTestClassInfo($phpUnitTestSuite, $testSuite);
foreach ($item['groups'] as $group) {
$list[$group][$item['name']] = $item;
}
return $list;
}
// Multiple test classes were found.
$list = [];
foreach ($phpUnitTestSuite->tests() as $testClass) {
if ($extension !== NULL && !str_starts_with($testClass->name(), "Drupal\\Tests\\{$extension}\\")) {
continue;
}
// Take the test suite name from the class namespace.
$testSuite = 'PHPUnit-' . TestDiscovery::getPhpunitTestSuite($testClass->name());
if (!empty($testSuites) && !in_array($testSuite, $testSuites, TRUE)) {
continue;
}
$item = $this->getTestClassInfo($testClass, $testSuite);
foreach ($item['groups'] as $group) {
$list[$group][$item['name']] = $item;
}
}
return $list;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.