Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6b0fbfb

Browse filesBrowse files
committed
Merge branch '5.4' into 6.3
* 5.4: fix typo CS fix [Serializer] Keep stack trace for enum value denormalizer error [Serializer] Fix partial denormalization with missing constructor arguments [Serializer] Moves dummy to fixtures folder
2 parents f99e1a0 + 449f224 commit 6b0fbfb
Copy full SHA for 6b0fbfb

File tree

Expand file treeCollapse file tree

13 files changed

+92
-17
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+92
-17
lines changed

‎src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private static function removeDir($dir)
265265
rmdir($dir);
266266
}
267267

268-
public static function setupBeforeClass(): void
268+
public static function setUpBeforeClass(): void
269269
{
270270
foreach (get_declared_classes() as $class) {
271271
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTestCase.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function testFirewalls()
242242
],
243243
], $listeners);
244244

245-
$this->assertFalse($container->hasAlias(UserCheckerInterface::class, 'No user checker alias is registered when custom user checker services are registered'));
245+
$this->assertFalse($container->hasAlias(UserCheckerInterface::class), 'No user checker alias is registered when custom user checker services are registered');
246246
}
247247

248248
public function testFirewallRequestMatchers()

‎src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CouchbaseBucketAdapterTest extends AdapterTestCase
3333
/** @var \CouchbaseBucket */
3434
protected static $client;
3535

36-
public static function setupBeforeClass(): void
36+
public static function setUpBeforeClass(): void
3737
{
3838
if (!CouchbaseBucketAdapter::isSupported()) {
3939
throw new SkippedTestSuiteError('Couchbase >= 2.6.0 < 3.0.0 is required.');

‎src/Symfony/Component/Cache/Tests/Adapter/CouchbaseCollectionAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/CouchbaseCollectionAdapterTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CouchbaseCollectionAdapterTest extends AdapterTestCase
3333
/** @var Collection */
3434
protected static $client;
3535

36-
public static function setupBeforeClass(): void
36+
public static function setUpBeforeClass(): void
3737
{
3838
if (!CouchbaseCollectionAdapter::isSupported()) {
3939
self::markTestSkipped('Couchbase >= 3.0.0 < 4.0.0 is required.');

‎src/Symfony/Component/Cache/Tests/Adapter/RedisArrayAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/RedisArrayAdapterTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RedisArrayAdapterTest extends AbstractRedisAdapterTestCase
2020
{
2121
public static function setUpBeforeClass(): void
2222
{
23-
parent::setupBeforeClass();
23+
parent::setUpBeforeClass();
2424
if (!class_exists(\RedisArray::class)) {
2525
throw new SkippedTestSuiteError('The RedisArray class is required.');
2626
}

‎src/Symfony/Component/Lock/Tests/Store/MongoDbStoreFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Tests/Store/MongoDbStoreFactoryTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class MongoDbStoreFactoryTest extends TestCase
2727
{
28-
public static function setupBeforeClass(): void
28+
public static function setUpBeforeClass(): void
2929
{
3030
if (!class_exists(Client::class)) {
3131
throw new SkippedTestSuiteError('The mongodb/mongodb package is required.');

‎src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MongoDbStoreTest extends AbstractStoreTestCase
3030
{
3131
use ExpiringStoreTestTrait;
3232

33-
public static function setupBeforeClass(): void
33+
public static function setUpBeforeClass(): void
3434
{
3535
if (!class_exists(Client::class)) {
3636
throw new SkippedTestSuiteError('The mongodb/mongodb package is required.');

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,32 +367,32 @@ protected function instantiateObject(array &$data, string $class, array &$contex
367367
} elseif ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {
368368
$parameterData = $data[$key];
369369
if (null === $parameterData && $constructorParameter->allowsNull()) {
370-
$params[] = null;
370+
$params[$paramName] = null;
371371
$unsetKeys[] = $key;
372372

373373
continue;
374374
}
375375

376376
try {
377-
$params[] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $attributeContext, $format);
377+
$params[$paramName] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $attributeContext, $format);
378378
} catch (NotNormalizableValueException $exception) {
379379
if (!isset($context['not_normalizable_value_exceptions'])) {
380380
throw $exception;
381381
}
382382

383383
$context['not_normalizable_value_exceptions'][] = $exception;
384-
$params[] = $parameterData;
384+
$params[$paramName] = $parameterData;
385385
}
386386

387387
$unsetKeys[] = $key;
388388
} elseif (\array_key_exists($key, $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? [])) {
389-
$params[] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
389+
$params[$paramName] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
390390
} elseif (\array_key_exists($key, $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? [])) {
391-
$params[] = $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
391+
$params[$paramName] = $this->defaultContext[self::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
392392
} elseif ($constructorParameter->isDefaultValueAvailable()) {
393-
$params[] = $constructorParameter->getDefaultValue();
393+
$params[$paramName] = $constructorParameter->getDefaultValue();
394394
} elseif (!($context[self::REQUIRE_ALL_PROPERTIES] ?? $this->defaultContext[self::REQUIRE_ALL_PROPERTIES] ?? false) && $constructorParameter->hasType() && $constructorParameter->getType()->allowsNull()) {
395-
$params[] = null;
395+
$params[$paramName] = null;
396396
} else {
397397
if (!isset($context['not_normalizable_value_exceptions'])) {
398398
$missingConstructorArguments[] = $constructorParameter->name;

‎src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
7777
return $type::from($data);
7878
} catch (\ValueError $e) {
7979
if (isset($context['has_constructor'])) {
80-
throw new InvalidArgumentException('The data must belong to a backed enumeration of type '.$type);
80+
throw new InvalidArgumentException('The data must belong to a backed enumeration of type '.$type, 0, $e);
8181
}
8282

8383
throw NotNormalizableValueException::createForUnexpectedDataType('The data must belong to a backed enumeration of type '.$type, $data, [$type], $context['deserialization_path'] ?? null, true, 0, $e);

‎src/Symfony/Component/Serializer/Tests/Php80Dummy.php renamed to ‎src/Symfony/Component/Serializer/Tests/Fixtures/Php80Dummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Fixtures/Php80Dummy.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Serializer\Tests;
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
1313

1414
final class Php80Dummy
1515
{
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
final class Php80WithOptionalConstructorParameter
15+
{
16+
public function __construct(
17+
public string $one,
18+
public string $two,
19+
public ?string $three = null,
20+
) {
21+
}
22+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Symfony\Component\Serializer\Tests\Fixtures\OtherSerializedNameDummy;
4242
use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy;
4343
use Symfony\Component\Serializer\Tests\Fixtures\Php74DummyPrivate;
44+
use Symfony\Component\Serializer\Tests\Fixtures\Php80Dummy;
4445
use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder;
4546
use Symfony\Component\Serializer\Tests\Normalizer\Features\AttributesTestTrait;
4647
use Symfony\Component\Serializer\Tests\Normalizer\Features\CacheableObjectAttributesTestTrait;
@@ -58,7 +59,6 @@
5859
use Symfony\Component\Serializer\Tests\Normalizer\Features\TypedPropertiesObject;
5960
use Symfony\Component\Serializer\Tests\Normalizer\Features\TypedPropertiesObjectWithGetters;
6061
use Symfony\Component\Serializer\Tests\Normalizer\Features\TypeEnforcementTestTrait;
61-
use Symfony\Component\Serializer\Tests\Php80Dummy;
6262

6363
/**
6464
* @author Kévin Dunglas <dunglas@gmail.com>

‎src/Symfony/Component/Serializer/Tests/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
6969
use Symfony\Component\Serializer\Tests\Fixtures\ObjectCollectionPropertyDummy;
7070
use Symfony\Component\Serializer\Tests\Fixtures\Php74Full;
71+
use Symfony\Component\Serializer\Tests\Fixtures\Php80WithOptionalConstructorParameter;
7172
use Symfony\Component\Serializer\Tests\Fixtures\Php80WithPromotedTypedConstructor;
7273
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
7374
use Symfony\Component\Serializer\Tests\Fixtures\TrueBuiltInDummy;
@@ -1502,6 +1503,58 @@ public function testSerializerUsesSupportedTypesMethod()
15021503
$serializer->denormalize('foo', Model::class, 'json');
15031504
$serializer->denormalize('foo', Model::class, 'json');
15041505
}
1506+
1507+
public function testPartialDenormalizationWithMissingConstructorTypes()
1508+
{
1509+
$json = '{"one": "one string", "three": "three string"}';
1510+
1511+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
1512+
1513+
$serializer = new Serializer(
1514+
[new ObjectNormalizer(null, null, null, $extractor)],
1515+
['json' => new JsonEncoder()]
1516+
);
1517+
1518+
try {
1519+
$serializer->deserialize($json, Php80WithOptionalConstructorParameter::class, 'json', [
1520+
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
1521+
]);
1522+
1523+
$this->fail();
1524+
} catch (\Throwable $th) {
1525+
$this->assertInstanceOf(PartialDenormalizationException::class, $th);
1526+
}
1527+
1528+
$this->assertInstanceOf(Php80WithOptionalConstructorParameter::class, $object = $th->getData());
1529+
1530+
$this->assertSame('one string', $object->one);
1531+
$this->assertFalse(isset($object->two));
1532+
$this->assertSame('three string', $object->three);
1533+
1534+
$exceptionsAsArray = array_map(function (NotNormalizableValueException $e): array {
1535+
return [
1536+
'currentType' => $e->getCurrentType(),
1537+
'expectedTypes' => $e->getExpectedTypes(),
1538+
'path' => $e->getPath(),
1539+
'useMessageForUser' => $e->canUseMessageForUser(),
1540+
'message' => $e->getMessage(),
1541+
];
1542+
}, $th->getErrors());
1543+
1544+
$expected = [
1545+
[
1546+
'currentType' => 'array',
1547+
'expectedTypes' => [
1548+
'unknown',
1549+
],
1550+
'path' => null,
1551+
'useMessageForUser' => true,
1552+
'message' => 'Failed to create object because the class misses the "two" property.',
1553+
],
1554+
];
1555+
1556+
$this->assertSame($expected, $exceptionsAsArray);
1557+
}
15051558
}
15061559

15071560
class Model

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.