From 37761e9fb13f327f7d956f85855cf5291b157b8c Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Wed, 19 Jun 2024 14:41:05 +0200 Subject: [PATCH] BUGFIX: Add test to prove that optional parameters are passed into unexpected slots when parameters in between are missing --- .../Domain/Schema/SchemaNormalizerTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Tests/Unit/Domain/Schema/SchemaNormalizerTest.php b/Tests/Unit/Domain/Schema/SchemaNormalizerTest.php index 08485b6..18727c3 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