You are here

public function PHPUnit_Util_TestDox_NamePrettifier::prettifyTestMethod in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/TestDox/NamePrettifier.php \PHPUnit_Util_TestDox_NamePrettifier::prettifyTestMethod()

Prettifies the name of a test method.

Parameters

string $name:

Return value

string

File

vendor/phpunit/phpunit/src/Util/TestDox/NamePrettifier.php, line 66

Class

PHPUnit_Util_TestDox_NamePrettifier
Prettifies class and method names for use in TestDox documentation.

Code

public function prettifyTestMethod($name) {
  $buffer = '';
  if (!is_string($name) || strlen($name) == 0) {
    return $buffer;
  }
  $string = preg_replace('#\\d+$#', '', $name, -1, $count);
  if (in_array($string, $this->strings)) {
    $name = $string;
  }
  elseif ($count == 0) {
    $this->strings[] = $string;
  }
  if (strpos($name, '_') !== false) {
    return str_replace('_', ' ', $name);
  }
  $max = strlen($name);
  if (substr($name, 0, 4) == 'test') {
    $offset = 4;
  }
  else {
    $offset = 0;
    $name[0] = strtoupper($name[0]);
  }
  $wasNumeric = false;
  for ($i = $offset; $i < $max; $i++) {
    if ($i > $offset && ord($name[$i]) >= 65 && ord($name[$i]) <= 90) {
      $buffer .= ' ' . strtolower($name[$i]);
    }
    else {
      $isNumeric = is_numeric($name[$i]);
      if (!$wasNumeric && $isNumeric) {
        $buffer .= ' ';
        $wasNumeric = true;
      }
      if ($wasNumeric && !$isNumeric) {
        $wasNumeric = false;
      }
      $buffer .= $name[$i];
    }
  }
  return $buffer;
}