Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6620ed4

Browse files
Add a test for self constructor promoted parameter
- Introduce `DummyWithSelfConstructorPromotedParameter` test class to validate the normalization/denormalization.
1 parent bd395bb commit 6620ed4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,18 @@ classMetadataFactory: new ClassMetadataFactory(new AttributeLoader()),
967967
$this->assertEquals(new DummyWithEnumUnion(EnumB::B), $serializer->denormalize($normalized, DummyWithEnumUnion::class));
968968
}
969969

970+
public function testDenormalizeSelfConstructorPromotedParameter()
971+
{
972+
$serializer = new Serializer([
973+
new ObjectNormalizer(
974+
propertyTypeExtractor: new PropertyInfoExtractor([], [new ReflectionExtractor()]),
975+
),
976+
]);
977+
978+
$normalized = $serializer->normalize(new DummyWithSelfConstructorPromotedParameter('A', new DummyWithSelfConstructorPromotedParameter('B')));
979+
$this->assertEquals(new DummyWithSelfConstructorPromotedParameter('A', new DummyWithSelfConstructorPromotedParameter('B')), $serializer->denormalize($normalized, DummyWithSelfConstructorPromotedParameter::class));
980+
}
981+
970982
#[RequiresMethod(ReflectionTypeResolver::class, 'resolve')]
971983
public function testDenormalizeUsesConstructorUnionTypeWhenExtractorIsLessPrecise()
972984
{
@@ -1954,6 +1966,15 @@ public function __construct(
19541966
}
19551967
}
19561968

1969+
class DummyWithSelfConstructorPromotedParameter
1970+
{
1971+
public function __construct(
1972+
public readonly string $name,
1973+
public readonly ?self $partner = null,
1974+
) {
1975+
}
1976+
}
1977+
19571978
class DummyWithIntOrString
19581979
{
19591980
public function __construct(

0 commit comments

Comments
 (0)