protected function TestFileParser::parseContents in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Test/RunTests/TestFileParser.php \Drupal\Core\Test\RunTests\TestFileParser::parseContents()
- 10 core/lib/Drupal/Core/Test/RunTests/TestFileParser.php \Drupal\Core\Test\RunTests\TestFileParser::parseContents()
Parse class names out of PHP file contents.
Parameters
string $contents: The contents of a PHP file.
Return value
string[] Array of fully qualified class names within the PHP file contents.
1 call to TestFileParser::parseContents()
- TestFileParser::getTestListFromFile in core/
lib/ Drupal/ Core/ Test/ RunTests/ TestFileParser.php - Gets the classes from a PHP file.
File
- core/
lib/ Drupal/ Core/ Test/ RunTests/ TestFileParser.php, line 40
Class
- TestFileParser
- Parses class names from PHP files without loading them.
Namespace
Drupal\Core\Test\RunTestsCode
protected function parseContents($contents) {
// Extract a potential namespace.
$namespace = FALSE;
if (preg_match('@^\\s*namespace ([^ ;]+)@m', $contents, $matches)) {
$namespace = $matches[1];
}
$test_list = [];
// Extract all class names. Abstract classes are excluded on purpose.
preg_match_all('@^\\s*(?!abstract\\s+)(?:final\\s+|\\s*)class ([^ ]+)@m', $contents, $matches);
if (!$namespace) {
$test_list = $matches[1];
}
else {
foreach ($matches[1] as $class_name) {
$namespace_class = $namespace . '\\' . $class_name;
$test_list[] = $namespace_class;
}
}
return $test_list;
}