Skip to content

Commit d8a80c9

Browse files
Merge branch '5.4' into 6.2
* 5.4: [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s [Intl] fix test [Intl] Use VarExporter::export() in PhpBundleWriter Use triggering class to generate baseline for deprecation messages from DebugClassLoader [Security] Fix false-string handling in RememberMeAuthenticator [CssSelector] Tests on Xpath translator will always pass [Serializer] Fix Normalizer not utilizing converted name for index variadic param [DepdencyInjection] Fix costly logic when checking errored definitions fix children cond [DoctrineBridge] Load refreshed user proxy [DependencyInjection] Don't ignore attributes on the actual decorator [FrameworkBundle] Prevent `cache:clear` to lose files on subsequent runs
2 parents 7be4b2f + 0a88ada commit d8a80c9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Normalizer/AbstractNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ protected function instantiateObject(array &$data, string $class, array &$contex
339339
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
340340
if ($constructorParameter->isVariadic()) {
341341
if ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {
342-
if (!\is_array($data[$paramName])) {
342+
if (!\is_array($data[$key])) {
343343
throw new RuntimeException(sprintf('Cannot create an instance of "%s" from serialized data because the variadic parameter "%s" can only accept an array.', $class, $constructorParameter->name));
344344
}
345345

346346
$variadicParameters = [];
347-
foreach ($data[$paramName] as $parameterKey => $parameterData) {
347+
foreach ($data[$key] as $parameterKey => $parameterData) {
348348
$variadicParameters[$parameterKey] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $attributeContext, $format);
349349
}
350350

Tests/Normalizer/AbstractNormalizerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
2121
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
2222
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
23+
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
2324
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
2425
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
2526
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
@@ -168,6 +169,7 @@ public function testObjectWithNullableNonOptionalConstructorArgumentWithoutInput
168169

169170
/**
170171
* @dataProvider getNormalizer
172+
* @dataProvider getNormalizerWithCustomNameConverter
171173
*/
172174
public function testObjectWithVariadicConstructorTypedArguments(AbstractNormalizer $normalizer)
173175
{
@@ -241,6 +243,25 @@ public static function getNormalizer()
241243
yield [new ObjectNormalizer(null, null, null, $extractor)];
242244
}
243245

246+
public static function getNormalizerWithCustomNameConverter()
247+
{
248+
$extractor = new PhpDocExtractor();
249+
$nameConverter = new class() implements NameConverterInterface {
250+
public function normalize(string $propertyName): string
251+
{
252+
return ucfirst($propertyName);
253+
}
254+
255+
public function denormalize(string $propertyName): string
256+
{
257+
return lcfirst($propertyName);
258+
}
259+
};
260+
261+
yield [new PropertyNormalizer(null, $nameConverter, $extractor)];
262+
yield [new ObjectNormalizer(null, $nameConverter, null, $extractor)];
263+
}
264+
244265
public function testIgnore()
245266
{
246267
$classMetadata = new ClassMetadata(IgnoreDummy::class);

0 commit comments

Comments
 (0)