Skip to content
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/ObjectMapper/ObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function doMap(object $source, object|string|null $target, \WeakMap $obj
}
}

if ($mappingToObject && $ctorArguments) {
if ($mappingToObject && $rootCall && $ctorArguments) {
foreach ($ctorArguments as $property => $value) {
if ($this->propertyIsMappable($refl, $property) && $this->propertyIsMappable($targetRefl, $property)) {
$mapToProperties[$property] = $value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty;

use Symfony\Component\ObjectMapper\Attribute\Map;

#[Map(target: ReadOnlyPromotedPropertyAMapped::class)]
final class ReadOnlyPromotedPropertyA
{
public function __construct(
public ReadOnlyPromotedPropertyB $b,
public string $var1,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty;

use Symfony\Component\ObjectMapper\Attribute\Map;

final class ReadOnlyPromotedPropertyAMapped
{
public function __construct(
public ReadOnlyPromotedPropertyBMapped $b,
public string $var1,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty;

use Symfony\Component\ObjectMapper\Attribute\Map;

#[Map(target: ReadOnlyPromotedPropertyBMapped::class)]
final class ReadOnlyPromotedPropertyB
{
public function __construct(
public string $var2,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty;

use Symfony\Component\ObjectMapper\Attribute\Map;

final class ReadOnlyPromotedPropertyBMapped
{
public function __construct(
public string $var2,
) {
}
}
22 changes: 22 additions & 0 deletions src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
use Symfony\Component\ObjectMapper\Tests\Fixtures\PromotedConstructor\Target as PromotedConstructorTarget;
use Symfony\Component\ObjectMapper\Tests\Fixtures\PromotedConstructorWithMetadata\Source as PromotedConstructorWithMetadataSource;
use Symfony\Component\ObjectMapper\Tests\Fixtures\PromotedConstructorWithMetadata\Target as PromotedConstructorWithMetadataTarget;
use Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty\ReadOnlyPromotedPropertyA;
use Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty\ReadOnlyPromotedPropertyAMapped;
use Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty\ReadOnlyPromotedPropertyB;
use Symfony\Component\ObjectMapper\Tests\Fixtures\ReadOnlyPromotedProperty\ReadOnlyPromotedPropertyBMapped;
use Symfony\Component\ObjectMapper\Tests\Fixtures\Recursion\AB;
use Symfony\Component\ObjectMapper\Tests\Fixtures\Recursion\Dto;
use Symfony\Component\ObjectMapper\Tests\Fixtures\ServiceLoadedValue\LoadedValueService;
Expand Down Expand Up @@ -632,4 +636,22 @@ public function testMapEmbeddedProperties()
$this->assertSame('12345', $user->address->zipcode);
$this->assertSame('Test City', $user->address->city);
}

public function testBugReportLazyLoadingPromotedReadonlyProperty()
{
$source = new ReadOnlyPromotedPropertyA(
b: new ReadOnlyPromotedPropertyB(
var2: 'bar',
),
var1: 'foo',
);

$mapper = new ObjectMapper();
$out = $mapper->map($source);

$this->assertInstanceOf(ReadOnlyPromotedPropertyAMapped::class, $out);
$this->assertInstanceOf(ReadOnlyPromotedPropertyBMapped::class, $out->b);
$this->assertSame('foo', $out->var1);
$this->assertSame('bar', $out->b->var2);
}
}