You are here

public static function TestDiscovery::parseTestClassSummary in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Test/TestDiscovery.php \Drupal\Core\Test\TestDiscovery::parseTestClassSummary()

Parses the phpDoc summary line of a test class.

Parameters

string $doc_comment:

Return value

string The parsed phpDoc summary line. An empty string is returned if no summary line can be parsed.

1 call to TestDiscovery::parseTestClassSummary()
TestDiscovery::getTestInfo in core/lib/Drupal/Core/Test/TestDiscovery.php
Retrieves information about a test class for UI purposes.

File

core/lib/Drupal/Core/Test/TestDiscovery.php, line 397

Class

TestDiscovery
Discovers available tests.

Namespace

Drupal\Core\Test

Code

public static function parseTestClassSummary($doc_comment) {

  // Normalize line endings.
  $doc_comment = preg_replace('/\\r\\n|\\r/', '\\n', $doc_comment);

  // Strip leading and trailing doc block lines.
  $doc_comment = substr($doc_comment, 4, -4);
  $lines = explode("\n", $doc_comment);
  $summary = [];

  // Add every line to the summary until the first empty line or annotation
  // is found.
  foreach ($lines as $line) {
    if (preg_match('/^[ ]*\\*$/', $line) || preg_match('/^[ ]*\\* \\@/', $line)) {
      break;
    }
    $summary[] = trim($line, ' *');
  }
  return implode(' ', $summary);
}