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

Breadcrumb

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

function NamePrettifier::prettifyTestClassName

@psalm-param class-string $className

File

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

Class

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

Namespace

PHPUnit\Logging\TestDox

Code

public function prettifyTestClassName(string $className) : string {
    if (class_exists($className)) {
        $classLevelTestDox = MetadataRegistry::parser()->forClass($className)
            ->isTestDox();
        if ($classLevelTestDox->isNotEmpty()) {
            $classLevelTestDox = $classLevelTestDox->asArray()[0];
            assert($classLevelTestDox instanceof TestDox);
            return $classLevelTestDox->text();
        }
    }
    $parts = explode('\\', $className);
    $className = array_pop($parts);
    if (str_ends_with($className, 'Test')) {
        $className = substr($className, 0, strlen($className) - strlen('Test'));
    }
    if (str_starts_with($className, 'Tests')) {
        $className = substr($className, strlen('Tests'));
    }
    elseif (str_starts_with($className, 'Test')) {
        $className = substr($className, strlen('Test'));
    }
    if (empty($className)) {
        $className = 'UnnamedTests';
    }
    if (!empty($parts)) {
        $parts[] = $className;
        $fullyQualifiedName = implode('\\', $parts);
    }
    else {
        $fullyQualifiedName = $className;
    }
    $result = preg_replace('/(?<=[[:lower:]])(?=[[:upper:]])/u', ' ', $className);
    if ($fullyQualifiedName !== $className) {
        return $result . ' (' . $fullyQualifiedName . ')';
    }
    return $result;
}
RSS feed
Powered by Drupal