function PhpUnitTestDiscovery::getTestListLimitedToDirectory

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Test/PhpUnitTestDiscovery.php \Drupal\Core\Test\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

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

File

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

Class

PhpUnitTestDiscovery
Discovers available tests using the PHPUnit API.

Namespace

Drupal\Core\Test

Code

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 ($phpUnitTestSuite->isEmpty()) {
      return [];
    }
    if ($extension !== NULL && !str_starts_with($phpUnitTestSuite->name(), "Drupal\\Tests\\{$extension}\\")) {
      return [];
    }
    // Take the test suite name from the class namespace.
    $testSuite = self::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 ($testClass->isEmpty()) {
      continue;
    }
    if ($extension !== NULL && !str_starts_with($testClass->name(), "Drupal\\Tests\\{$extension}\\")) {
      continue;
    }
    // Take the test suite name from the class namespace.
    $testSuite = self::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.