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

Breadcrumb

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

function NamePrettifier::mapTestMethodParameterNamesToProvidedDataValues

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

File

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

Class

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

Namespace

PHPUnit\Logging\TestDox

Code

private function mapTestMethodParameterNamesToProvidedDataValues(TestCase $test, bool $colorize) : array {
    assert(method_exists($test, $test->name()));
    
    /** @noinspection PhpUnhandledExceptionInspection */
    $reflector = new ReflectionMethod($test::class, $test->name());
    $providedData = [];
    $providedDataValues = array_values($test->providedData());
    $i = 0;
    $providedData['$_dataName'] = $test->dataName();
    foreach ($reflector->getParameters() as $parameter) {
        if (!array_key_exists($i, $providedDataValues) && $parameter->isDefaultValueAvailable()) {
            $providedDataValues[$i] = $parameter->getDefaultValue();
        }
        $value = $providedDataValues[$i++] ?? null;
        if (is_object($value)) {
            $reflector = new ReflectionObject($value);
            if ($reflector->isEnum()) {
                $enumReflector = new ReflectionEnum($value);
                if ($enumReflector->isBacked()) {
                    $value = $value->value;
                }
                else {
                    $value = $value->name;
                }
            }
            elseif ($reflector->hasMethod('__toString')) {
                $value = (string) $value;
            }
            else {
                $value = $value::class;
            }
        }
        if (!is_scalar($value)) {
            $value = gettype($value);
            if ($value === 'NULL') {
                $value = 'null';
            }
        }
        if (is_bool($value) || is_int($value) || is_float($value)) {
            $value = (new Exporter())->export($value);
        }
        if ($value === '') {
            if ($colorize) {
                $value = Color::colorize('dim,underlined', 'empty');
            }
            else {
                $value = "''";
            }
        }
        $providedData['$' . $parameter->getName()] = str_replace('$', '\\$', $value);
    }
    if ($colorize) {
        $providedData = array_map(static fn($value) => Color::colorize('fg-cyan', Color::visualizeWhitespace((string) $value, true)), $providedData);
    }
    return $providedData;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal