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\TestDoxCode
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;
}