function PhpUnitTestDiscovery::getTestList

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Test/PhpUnitTestDiscovery.php \Drupal\Core\Test\PhpUnitTestDiscovery::getTestList()

Returns a list of tests from a TestSuite object.

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> $testGroups: (optional) An array of test groups to filter the discovery for.

Return value

GroupedTestClassInfoList 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::getTestList()
PhpUnitTestDiscovery::getTestClasses in core/lib/Drupal/Core/Test/PhpUnitTestDiscovery.php
Discovers available tests.

File

core/lib/Drupal/Core/Test/PhpUnitTestDiscovery.php, line 212

Class

PhpUnitTestDiscovery
Discovers available tests using the PHPUnit API.

Namespace

Drupal\Core\Test

Code

private function getTestList(TestSuite $phpUnitTestSuite, ?string $extension, array $testGroups) : array {
  $list = [];
  foreach ($phpUnitTestSuite->tests() as $testSuite) {
    foreach ($testSuite->tests() as $testClass) {
      if ($testClass->isEmpty()) {
        continue;
      }
      if ($extension !== NULL && !str_starts_with($testClass->name(), "Drupal\\Tests\\{$extension}\\")) {
        continue;
      }
      $item = $this->getTestClassInfo($testClass, $testSuite->name());
      // Skip tests whose groups are not in the required ones.
      if (!empty($testGroups) && empty(array_intersect($item['groups'], $testGroups))) {
        continue;
      }
      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.