Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Fix optional parameter handling in deserializer #22

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Classes/Domain/Schema/SchemaDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions Tests/Unit/Domain/Schema/SchemaNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading