Skip to content

Commit 90251c9

Browse files
committed
add test
1 parent 4b3dcf1 commit 90251c9

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,24 @@ public function testNormalizationWithMaxDepthOnStdclassObjectDoesNotThrowWarning
11291129

11301130
$this->assertSame(['string' => 'yes'], $normalized);
11311131
}
1132+
1133+
public function testDenormalizeCollectionOfScalarTypesPropertyWithPhpDocExtractor()
1134+
{
1135+
$normalizer = new AbstractObjectNormalizerWithMetadataAndPhpDocExtractor();
1136+
$data = [
1137+
'type' => 'foo',
1138+
'values' => [
1139+
['1'],
1140+
['2'],
1141+
['3'],
1142+
['4'],
1143+
['5'],
1144+
],
1145+
];
1146+
$expected = new ScalarCollectionDocBlockDummy([[1], [2], [3], [4], [5]]);
1147+
1148+
$this->assertEquals($expected, $normalizer->denormalize($data, ScalarCollectionDocBlockDummy::class));
1149+
}
11321150
}
11331151

11341152
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
@@ -1540,3 +1558,50 @@ public function __construct(
15401558
) {
15411559
}
15421560
}
1561+
1562+
#[DiscriminatorMap('type', ['foo' => ScalarCollectionDocBlockDummy::class])]
1563+
class ScalarCollectionDocBlockDummy
1564+
{
1565+
/**
1566+
* @param array<int, array<int, string>>|null $values
1567+
*/
1568+
public function __construct(
1569+
private readonly ?array $values = null,
1570+
) {
1571+
}
1572+
1573+
/** @return array<int, array<int, string>>|null */
1574+
public function getValues(): ?array
1575+
{
1576+
return $this->values;
1577+
}
1578+
}
1579+
1580+
class AbstractObjectNormalizerWithMetadataAndPhpDocExtractor extends AbstractObjectNormalizer
1581+
{
1582+
public function __construct()
1583+
{
1584+
parent::__construct(new ClassMetadataFactory(new AttributeLoader()), null, new PropertyInfoExtractor([], [new PhpDocExtractor()]));
1585+
}
1586+
1587+
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
1588+
{
1589+
return [];
1590+
}
1591+
1592+
protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []): mixed
1593+
{
1594+
return null;
1595+
}
1596+
1597+
protected function setAttributeValue(object $object, string $attribute, mixed $value, ?string $format = null, array $context = []): void
1598+
{
1599+
}
1600+
1601+
public function getSupportedTypes(?string $format): array
1602+
{
1603+
return [
1604+
'*' => false,
1605+
];
1606+
}
1607+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy