Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when replacing placeholders in testdox using an associative array #3398

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Util/TestDox/NamePrettifier.php
Expand Up @@ -158,11 +158,15 @@ private function mapTestMethodParameterNamesToProvidedDataValues(TestCase $test)
{
$reflector = new \ReflectionMethod(\get_class($test), $test->getName(false));
$providedData = [];
$providedDataValues = $test->getProvidedData();
$providedDataValues = \array_values($test->getProvidedData());
$i = 0;

foreach ($reflector->getParameters() as $parameter) {
$value = $providedDataValues[$i++];
if (!\array_key_exists($i, $providedDataValues) && $parameter->isDefaultValueAvailable()) {
$providedDataValues[$i] = $parameter->getDefaultValue();
}

$value = $providedDataValues[$i++] ?? null;

if (\is_object($value)) {
$reflector = new \ReflectionObject($value);
Expand Down
54 changes: 54 additions & 0 deletions tests/unit/Util/TestDox/NamePrettifierTest.php
Expand Up @@ -57,4 +57,58 @@ public function testTestNameIsNotGroupedWhenNotInSequence(): void
$this->assertEquals('Sets redirect header on 301', $this->namePrettifier->prettifyTestMethod('testSetsRedirectHeaderOn301'));
$this->assertEquals('Sets redirect header on 302', $this->namePrettifier->prettifyTestMethod('testSetsRedirectHeaderOn302'));
}

public function testPhpDoxIgnoreDataKeys(): void
{
$test = new class extends TestCase {
public function __construct()
{
parent::__construct('testAddition', [
'augend' => 1,
'addend' => 2,
'result' => 3,
]);
}

public function testAddition(int $augend, int $addend, int $result): void
{
}

public function getAnnotations(): array
{
return [
'method' => [
'testdox' => ['$augend + $addend = $result'],
],
];
}
};

$this->assertEquals('1 + 2 = 3', $this->namePrettifier->prettifyTestCase($test));
}

public function testPhpDoxUsesDefaultValue(): void
{
$test = new class extends TestCase {
public function __construct()
{
parent::__construct('testAddition', []);
}

public function testAddition(int $augend = 1, int $addend = 2, int $result = 3): void
{
}

public function getAnnotations(): array
{
return [
'method' => [
'testdox' => ['$augend + $addend = $result'],
],
];
}
};

$this->assertEquals('1 + 2 = 3', $this->namePrettifier->prettifyTestCase($test));
}
}