From cf85ec1d33187b113c60b2e35a78f5056e2a35e6 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 20 Jul 2024 12:15:46 +0200 Subject: [PATCH] Increase test coverage to 100% --- src/JsonMapper.php | 2 +- tests/ArrayTest.php | 14 ++++++++++++++ tests/support/JsonMapperTest/VariadicArray.php | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/JsonMapper.php b/src/JsonMapper.php index 40ad5bdf3..5496d2878 100644 --- a/src/JsonMapper.php +++ b/src/JsonMapper.php @@ -833,7 +833,7 @@ protected function isArrayOfType($strType) /** * Returns true if accessor is a method and has only one parameter - * which is variadic. + * which is variadic ("...$args"). * * @param ReflectionMethod|ReflectionProperty|null $accessor accessor * to set value diff --git a/tests/ArrayTest.php b/tests/ArrayTest.php index 3194e301c..1daee0645 100644 --- a/tests/ArrayTest.php +++ b/tests/ArrayTest.php @@ -545,6 +545,20 @@ public function testMapArrayFromVariadicFunctionWithObjectType() $this->assertSame('2014-01-02', $variadicArray[0]->format('Y-m-d')); $this->assertSame('2014-05-07', $variadicArray[1]->format('Y-m-d')); } + + /** + * Test the "if (count($parameters) !== 1) {" condition in "hasVariadicArrayType()" + */ + public function testMapArrayVariadicMethodWithMultipleParams() + { + $jm = new JsonMapper(); + $sn = $jm->map( + json_decode('{"multipleParams":[23]}'), + new JsonMapperTest_VariadicArray() + ); + + $this->assertSame([23], $sn->multipleParamsVal); + } } ?> diff --git a/tests/support/JsonMapperTest/VariadicArray.php b/tests/support/JsonMapperTest/VariadicArray.php index 8929a8cf4..4450dc5cd 100644 --- a/tests/support/JsonMapperTest/VariadicArray.php +++ b/tests/support/JsonMapperTest/VariadicArray.php @@ -30,6 +30,8 @@ class JsonMapperTest_VariadicArray */ private $variadicInt; + public $multipleParamsVal; + /** * @param DateTime[] $items * @@ -69,5 +71,10 @@ public function setVariadicInt(int ...$items): self return $this; } + + public function setMultipleParams(array $param, int ...$dummy) + { + $this->multipleParamsVal = $param; + } } ?>