From 929c2330cc056e75e6fe9eacd36bfb2dce354b68 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 8 Feb 2024 15:59:02 +0000 Subject: [PATCH] Fix mapping properties with null values --- src/Hydrator/HydratorUtil.php | 2 +- test/Hydrator/HydratorUtilTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Hydrator/HydratorUtil.php b/src/Hydrator/HydratorUtil.php index d0e5071..f08d32a 100644 --- a/src/Hydrator/HydratorUtil.php +++ b/src/Hydrator/HydratorUtil.php @@ -259,7 +259,7 @@ public static function getMappedProperties(array $data, array $map): array { $mapped = []; foreach ($map as $old => $new) { - if (isset($data[$old])) { + if (array_key_exists($old, $data)) { $mapped[$new] = $data[$old]; } } diff --git a/test/Hydrator/HydratorUtilTest.php b/test/Hydrator/HydratorUtilTest.php index 8e11da8..152fe09 100644 --- a/test/Hydrator/HydratorUtilTest.php +++ b/test/Hydrator/HydratorUtilTest.php @@ -423,6 +423,16 @@ public function testGetMappedProperties(): void self::assertSame($expected, $actual); } + public function testGetMappedPropertiesReturnsNulls(): void + { + $expected = ['b' => null]; + $map = ['a' => 'b']; + $data = ['a' => null]; + + $actual = HydratorUtil::getMappedProperties($data, $map); + self::assertSame($expected, $actual); + } + public function testExtractObjectArrayExtracts(): void { $expected = [