Skip to content

Commit bb28f4c

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: separate the property info and write info extractors add missing assertion [Filesystem] Run high-deps tests with Process 7
2 parents 440675f + e05d8c6 commit bb28f4c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ final class ObjectNormalizer extends AbstractObjectNormalizer
3636

3737
protected PropertyAccessorInterface $propertyAccessor;
3838
protected $propertyInfoExtractor;
39+
private $writeInfoExtractor;
3940

4041
private readonly \Closure $objectClassResolver;
4142

@@ -51,6 +52,7 @@ public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory
5152

5253
$this->objectClassResolver = ($objectClassResolver ?? static fn ($class) => \is_object($class) ? $class::class : $class)(...);
5354
$this->propertyInfoExtractor = $propertyInfoExtractor ?: new ReflectionExtractor();
55+
$this->writeInfoExtractor = new ReflectionExtractor();
5456
}
5557

5658
public function getSupportedTypes(?string $format): array
@@ -174,8 +176,15 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
174176
return $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
175177
}
176178

177-
return $this->propertyInfoExtractor->isWritable($class, $attribute)
178-
|| ($writeInfo = $this->propertyInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType();
179+
if ($this->propertyInfoExtractor->isWritable($class, $attribute)) {
180+
return true;
181+
}
182+
183+
if (($writeInfo = $this->writeInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType()) {
184+
return true;
185+
}
186+
187+
return false;
179188
}
180189

181190
private function hasAttributeAccessorMethod(string $class, string $attribute): bool

src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ public function testDecodeEmptyData()
214214

215215
public function testMultipleEmptyHeaderNamesWithSeparator()
216216
{
217-
$this->encoder->decode(',.
218-
,', 'csv');
217+
$this->assertSame([['', [1 => '']]], $this->encoder->decode(',.
218+
,', 'csv'));
219219
}
220220

221221
public function testEncodeVariableStructure()

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ public function testConstructorWithObjectDenormalize()
265265
$this->assertEquals('bar', $obj->bar);
266266
}
267267

268+
public function testConstructorWithObjectDenormalizeUsingPropertyInfoExtractor()
269+
{
270+
$serializer = $this->createMock(ObjectSerializerNormalizer::class);
271+
$normalizer = new ObjectNormalizer(null, null, null, null, null, null, [], new PropertyInfoExtractor());
272+
$normalizer->setSerializer($serializer);
273+
274+
$data = new \stdClass();
275+
$data->foo = 'foo';
276+
$data->bar = 'bar';
277+
$data->baz = true;
278+
$data->fooBar = 'foobar';
279+
$obj = $normalizer->denormalize($data, ObjectConstructorDummy::class, 'any');
280+
$this->assertEquals('foo', $obj->getFoo());
281+
$this->assertEquals('bar', $obj->bar);
282+
}
283+
268284
public function testConstructorWithObjectTypeHintDenormalize()
269285
{
270286
$data = [

0 commit comments

Comments
 (0)