diff --git a/Classes/Domain/Schema/SchemaDenormalizer.php b/Classes/Domain/Schema/SchemaDenormalizer.php index 559ca72..e2b7804 100644 --- a/Classes/Domain/Schema/SchemaDenormalizer.php +++ b/Classes/Domain/Schema/SchemaDenormalizer.php @@ -88,7 +88,8 @@ private static function convertValueObject(array|int|float|string|bool $value, s $parameterReflections = $reflection->getConstructor()->getParameters(); $convertedArguments = []; if (is_array($value)) { - foreach ($parameterReflections as $name => $reflectionParameter) { + foreach ($parameterReflections as $reflectionParameter) { + $name = $reflectionParameter->getName(); $type = $reflectionParameter->getType(); if ($reflectionParameter->isDefaultValueAvailable() && !array_key_exists($reflectionParameter->getName(), $value)) { continue; diff --git a/Tests/Unit/Domain/Schema/SchemaNormalizerTest.php b/Tests/Unit/Domain/Schema/SchemaNormalizerTest.php index 08485b6..2f136e7 100644 --- a/Tests/Unit/Domain/Schema/SchemaNormalizerTest.php +++ b/Tests/Unit/Domain/Schema/SchemaNormalizerTest.php @@ -13,6 +13,30 @@ final class SchemaNormalizerTest extends TestCase { + public static function denormalizeObjectsWithOptionalParametersDataProvider(): \Generator + { + yield 'min PostalAddress' => [ + Fixtures\PostalAddress::class, + ['streetAddress' => 'Sesamstraße 42', 'addressRegion' => 'Muppetingen'], + new Fixtures\PostalAddress(streetAddress: 'Sesamstraße 42', addressRegion: 'Muppetingen') + ]; + yield 'PostalAddress with missing parameter in between' => [ + Fixtures\PostalAddress::class, + ['streetAddress' => 'Dämonenweg 23', 'addressRegion' => 'Hölle', 'postOfficeBoxNumber' => '666'], + new Fixtures\PostalAddress(streetAddress: 'Dämonenweg 23', addressRegion: 'Hölle', postOfficeBoxNumber: '666') + ]; + } + + /** + * @dataProvider denormalizeObjectsWithOptionalParametersDataProvider + * @test + */ + public function denormalizeObjectsWithOptionalParameters(mixed $type, mixed $data, mixed $expected): void + { + Assert::assertEquals($expected, SchemaDenormalizer::denormalizeValue($data, $type)); + } + + /** * @dataProvider valueNormalizationPairs * @test