function TestDiscovery::getTestInfo
Retrieves information about a test class for UI purposes.
Parameters
string $classname: The test classname.
string $doc_comment: (optional) The class PHPDoc comment. If not passed in reflection will be used but this is very expensive when parsing all the test classes.
Return value
array An associative array containing:
- name: The test class name.
- description: The test (PHPDoc) summary.
- group: The test's first @group (parsed from PHPDoc annotations).
- groups: All of the test's @group annotations, as an array (parsed from PHPDoc annotations).
Throws
\Drupal\Core\Test\Exception\MissingGroupException If the class does not have a @group annotation.
5 calls to TestDiscovery::getTestInfo()
- TestDiscovery::getTestClasses in core/lib/ Drupal/ Core/ Test/ TestDiscovery.php 
- Discovers all available tests in all extensions.
- TestDiscoveryTest::testGetTestInfoEmptyDocblock in core/tests/ Drupal/ Tests/ Core/ Test/ TestDiscoveryTest.php 
- Ensure that classes are not reflected when the docblock is empty.
- TestDiscoveryTest::testTestInfoParser in core/tests/ Drupal/ Tests/ Core/ Test/ TestDiscoveryTest.php 
- @covers ::getTestInfo[[api-linebreak]] @dataProvider infoParserProvider
- TestDiscoveryTest::testTestInfoParserMissingGroup in core/tests/ Drupal/ Tests/ Core/ Test/ TestDiscoveryTest.php 
- @covers ::getTestInfo[[api-linebreak]]
- TestDiscoveryTest::testTestInfoParserMissingSummary in core/tests/ Drupal/ Tests/ Core/ Test/ TestDiscoveryTest.php 
- @covers ::getTestInfo[[api-linebreak]]
File
- 
              core/lib/ Drupal/ Core/ Test/ TestDiscovery.php, line 312 
Class
- TestDiscovery
- Discovers available tests.
Namespace
Drupal\Core\TestCode
public static function getTestInfo($classname, $doc_comment = NULL) {
  if ($doc_comment === NULL) {
    $reflection = new \ReflectionClass($classname);
    $doc_comment = $reflection->getDocComment();
  }
  $info = [
    'name' => $classname,
  ];
  $annotations = [];
  // Look for annotations, allow an arbitrary amount of spaces before the
  // * but nothing else.
  preg_match_all('/^[ ]*\\* \\@([^\\s]*) (.*$)/m', $doc_comment, $matches);
  if (isset($matches[1])) {
    foreach ($matches[1] as $key => $annotation) {
      // For historical reasons, there is a single-value 'group' result key
      // and a 'groups' key as an array.
      if ($annotation === 'group') {
        $annotations['groups'][] = $matches[2][$key];
      }
      if (!empty($annotations[$annotation])) {
        // Only @group is allowed to have more than one annotation, in the
        // 'groups' key. Other annotations only have one value per key.
        continue;
      }
      $annotations[$annotation] = $matches[2][$key];
    }
  }
  if (empty($annotations['group'])) {
    // Concrete tests must have a group.
    throw new MissingGroupException(sprintf('Missing @group annotation in %s', $classname));
  }
  $info['group'] = $annotations['group'];
  $info['groups'] = $annotations['groups'];
  $info['type'] = 'PHPUnit-' . static::getPhpunitTestSuite($classname);
  if (!empty($annotations['coversDefaultClass'])) {
    $info['description'] = 'Tests ' . $annotations['coversDefaultClass'] . '.';
  }
  else {
    $info['description'] = static::parseTestClassSummary($doc_comment);
  }
  return $info;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
