Skip to content

Commit

Permalink
Increase test coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
cweiske committed Jul 20, 2024
1 parent 064310c commit cf85ec1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/JsonMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

?>
7 changes: 7 additions & 0 deletions tests/support/JsonMapperTest/VariadicArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class JsonMapperTest_VariadicArray
*/
private $variadicInt;

public $multipleParamsVal;

/**
* @param DateTime[] $items
*
Expand Down Expand Up @@ -69,5 +71,10 @@ public function setVariadicInt(int ...$items): self

return $this;
}

public function setMultipleParams(array $param, int ...$dummy)
{
$this->multipleParamsVal = $param;
}
}
?>

0 comments on commit cf85ec1

Please sign in to comment.