From 22b79c700c37ff62a3bd85a60734d637827d3106 Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Mon, 12 Nov 2018 18:47:37 -0200 Subject: [PATCH] Fix bug when replacing testdox parameters --- src/Util/TestDox/NamePrettifier.php | 8 ++- .../unit/Util/TestDox/NamePrettifierTest.php | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/Util/TestDox/NamePrettifier.php b/src/Util/TestDox/NamePrettifier.php index e3cd74a450f..ce19d8821f9 100644 --- a/src/Util/TestDox/NamePrettifier.php +++ b/src/Util/TestDox/NamePrettifier.php @@ -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); diff --git a/tests/unit/Util/TestDox/NamePrettifierTest.php b/tests/unit/Util/TestDox/NamePrettifierTest.php index 1c215bff358..a6f738765bf 100644 --- a/tests/unit/Util/TestDox/NamePrettifierTest.php +++ b/tests/unit/Util/TestDox/NamePrettifierTest.php @@ -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)); + } }