Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NamePrettifier.php

function NamePrettifier::prettifyTestMethodName

1 call to NamePrettifier::prettifyTestMethodName()
NamePrettifier::prettifyTestCase in vendor/phpunit/phpunit/src/Logging/TestDox/NamePrettifier.php

File

vendor/phpunit/phpunit/src/Logging/TestDox/NamePrettifier.php, line 113

Class

NamePrettifier
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Namespace

PHPUnit\Logging\TestDox

Code

public function prettifyTestMethodName(string $name) : string {
    if ($name === '') {
        return '';
    }
    $string = rtrim($name, '0123456789');
    if (array_key_exists($string, self::$strings)) {
        $name = $string;
    }
    elseif ($string === $name) {
        self::$strings[$string] = 1;
    }
    if (str_starts_with($name, 'test_')) {
        $name = substr($name, 5);
    }
    elseif (str_starts_with($name, 'test')) {
        $name = substr($name, 4);
    }
    if ($name === '') {
        return '';
    }
    $name[0] = strtoupper($name[0]);
    $noUnderscore = str_replace('_', ' ', $name);
    if ($noUnderscore !== $name) {
        return trim($noUnderscore);
    }
    $wasNumeric = false;
    $buffer = '';
    $len = strlen($name);
    for ($i = 0; $i < $len; $i++) {
        if ($i > 0 && $name[$i] >= 'A' && $name[$i] <= 'Z') {
            $buffer .= ' ' . strtolower($name[$i]);
        }
        else {
            $isNumeric = $name[$i] >= '0' && $name[$i] <= '9';
            if (!$wasNumeric && $isNumeric) {
                $buffer .= ' ';
                $wasNumeric = true;
            }
            if ($wasNumeric && !$isNumeric) {
                $wasNumeric = false;
            }
            $buffer .= $name[$i];
        }
    }
    return $buffer;
}
RSS feed
Powered by Drupal