Skip to content

Commit

Permalink
Merge pull request #4 from kynx/get-mapped-properties-with-nulls
Browse files Browse the repository at this point in the history
Fix mapping properties with null values
  • Loading branch information
kynx authored Feb 8, 2024
2 parents 8efabb0 + 929c233 commit 170b2bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Hydrator/HydratorUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/Hydrator/HydratorUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 170b2bb

Please sign in to comment.