public static function TestDiscovery::getTestInfo in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/TestDiscovery.php \Drupal\simpletest\TestDiscovery::getTestInfo()
Retrieves information about a test class for UI purposes.
Parameters
string $class: 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).
- requires: An associative array containing test requirements parsed from
PHPDoc annotations:
- module: List of Drupal module extension names the test depends on.
Throws
\Drupal\simpletest\Exception\MissingGroupException If the class does not have a @group annotation.
7 calls to TestDiscovery::getTestInfo()
- SimpletestResultsForm::addResultForm in core/
modules/ simpletest/ src/ Form/ SimpletestResultsForm.php - Adds the result form to a $form.
- simpletest_run_tests in core/
modules/ simpletest/ simpletest.module - Runs tests.
- TestDiscovery::getTestClasses in core/
modules/ simpletest/ src/ TestDiscovery.php - Discovers all available tests in all extensions.
- TestInfoParsingTest::testTestInfoParser in core/
modules/ simpletest/ tests/ src/ Unit/ TestInfoParsingTest.php - @covers ::getTestInfo @dataProvider infoParserProvider
- TestInfoParsingTest::testTestInfoParserMissingGroup in core/
modules/ simpletest/ tests/ src/ Unit/ TestInfoParsingTest.php - @covers ::getTestInfo @expectedException \Drupal\simpletest\Exception\MissingGroupException @expectedExceptionMessage Missing @group annotation in Drupal\field\Tests\BulkDeleteTest
File
- core/
modules/ simpletest/ src/ TestDiscovery.php, line 304 - Contains \Drupal\simpletest\TestDiscovery.
Class
- TestDiscovery
- Discovers available tests.
Namespace
Drupal\simpletestCode
public static function getTestInfo($classname, $doc_comment = NULL) {
if (!$doc_comment) {
$reflection = new \ReflectionClass($classname);
$doc_comment = $reflection
->getDocComment();
}
$info = array(
'name' => $classname,
);
$annotations = array();
// 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) {
if (!empty($annotations[$annotation])) {
// Only have the first match per annotation. This deals with
// multiple @group annotations.
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));
}
// Force all PHPUnit tests into the same group.
if (static::isUnitTest($classname)) {
$info['group'] = 'PHPUnit';
}
else {
$info['group'] = $annotations['group'];
}
if (!empty($annotations['coversDefaultClass'])) {
$info['description'] = 'Tests ' . $annotations['coversDefaultClass'] . '.';
}
else {
$info['description'] = static::parseTestClassSummary($doc_comment);
}
if (isset($annotations['dependencies'])) {
$info['requires']['module'] = array_map('trim', explode(',', $annotations['dependencies']));
}
return $info;
}