Skip to content

Commit ffb1dbc

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: fix high deps tests [ObjectMapper] Fix mapping for missing source properties [HttpFoundation] Fix double-prefixing of session keys when using redis/memcached [TypeInfo] Fix static type resolution when called class is in different namespace [FrameworkBundle] Revert destination file change for secrets:decrypt-to-local [Process] Ignore invalid env var names [FrameworkBundle] Don't list ExpressionConfigurator if expression-language is not installed on reference config shape [JsonStreamer] Fix memory leak by caching stream readers/writers [FrameworkBundle] Skip extensions with empty configuration in reference.php Also bypass `Return-Path` header within `MicrosoftGraphApiTransport`
2 parents 87e54fc + e483f87 commit ffb1dbc

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ObjectMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ private function doMap(object $source, object|string|null $target, \WeakMap $obj
155155
}
156156

157157
if (!$mappings && $targetRefl->hasProperty($propertyName)) {
158+
if (!$this->isReadable($source, $propertyName)) {
159+
continue;
160+
}
161+
158162
$sourceProperty = $refl->getProperty($propertyName);
159163
if ($refl->isInstance($source) && !$sourceProperty->isInitialized($source)) {
160164
continue;

Tests/ObjectMapperTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,4 +648,25 @@ public function testBugReportLazyLoadingPromotedReadonlyProperty()
648648
$this->assertSame('foo', $out->var1);
649649
$this->assertSame('bar', $out->b->var2);
650650
}
651+
652+
public function testMissingSourcePropertiesAreIgnored()
653+
{
654+
$mapper = new ObjectMapper();
655+
$source = new class {
656+
public string $name = 'test';
657+
};
658+
$target = $mapper->map($source, new class {
659+
public string $name;
660+
public bool $withDefault = true;
661+
public string $withoutDefault;
662+
});
663+
664+
$this->assertSame('test', $target->name);
665+
$this->assertTrue($target->withDefault);
666+
667+
$this->assertFalse(
668+
(new \ReflectionProperty($target, 'withoutDefault'))->isInitialized($target),
669+
'Property without default value should remain uninitialized'
670+
);
671+
}
651672
}

0 commit comments

Comments
 (0)