Skip to content

Commit

Permalink
Fix bug when replacing testdox parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos committed Nov 12, 2018
1 parent bdeb99a commit 22b79c7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
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));
}
}

0 comments on commit 22b79c7

Please sign in to comment.