Skip to content

Commit feaf837

Browse files
Merge branch '7.2' into 7.3
* 7.2: - [Console] Table counts wrong column width when using colspan and `setColumnMaxWidth()` [Console] Table counts wrong number of padding symbols in `renderCell()` method when cell contain unicode variant selector [Cache] Fix using a `ChainAdapter` as an adapter for a pool [Serializer] Fix collect_denormalization_errors flag in defaultContext [TypeInfo] Fix handling `ConstFetchNode` [VarDumper] Avoid deprecated call in PgSqlCaster Fix command option mode (InputOption::VALUE_REQUIRED) use an EOL-agnostic approach to parse class uses [Uid] Improve entropy of the increment for UUIDv7 [HttpKernel] Fix `#[MapUploadedFile]` handling for optional file uploads
2 parents d3cf71f + d84f0b7 commit feaf837

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
213213
throw new NotNormalizableValueException(\sprintf('Could not denormalize object of type "%s", no supporting normalizer found.', $type));
214214
}
215215

216-
if (isset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS]) || isset($this->defaultContext[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS])) {
216+
if ((isset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS]) || isset($this->defaultContext[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS])) && !isset($context['not_normalizable_value_exceptions'])) {
217217
unset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS]);
218218
$context['not_normalizable_value_exceptions'] = [];
219219
$errors = &$context['not_normalizable_value_exceptions'];

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ public function testDoesntHaveIssuesWithUnionConstTypes()
747747
$serializer = new Serializer([new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer]);
748748

749749
$this->assertSame('bar', $serializer->denormalize(['foo' => 'bar'], (new class {
750+
public const TEST = 'me';
751+
750752
/** @var self::*|null */
751753
public $foo;
752754
})::class)->foo);

Tests/SerializerTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,54 @@ public function testCollectDenormalizationErrorsDefaultContext()
17141714

17151715
$serializer->denormalize($data, DummyWithVariadicParameter::class);
17161716
}
1717+
1718+
public function testDenormalizationFailsWithMultipleErrorsInDefaultContext()
1719+
{
1720+
$serializer = new Serializer(
1721+
[new DateTimeNormalizer(), new ObjectNormalizer()],
1722+
[],
1723+
[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true]
1724+
);
1725+
1726+
$data = ['date' => '', 'unknown' => null];
1727+
1728+
try {
1729+
$serializer->denormalize($data, DummyEntityWithStringAndDateTime::class);
1730+
$this->fail('Expected PartialDenormalizationException was not thrown');
1731+
} catch (PartialDenormalizationException $e) {
1732+
$this->assertIsArray($e->getErrors());
1733+
$this->assertCount(2, $e->getErrors(), 'Expected two denormalization errors');
1734+
1735+
$exceptionsAsArray = array_map(function (NotNormalizableValueException $ex): array {
1736+
return [
1737+
'currentType' => $ex->getCurrentType(),
1738+
'expectedTypes' => $ex->getExpectedTypes(),
1739+
'path' => $ex->getPath(),
1740+
'useMessageForUser' => $ex->canUseMessageForUser(),
1741+
'message' => $ex->getMessage(),
1742+
];
1743+
}, $e->getErrors());
1744+
1745+
$expected = [
1746+
[
1747+
'currentType' => 'null',
1748+
'expectedTypes' => ['string'],
1749+
'path' => 'bar',
1750+
'useMessageForUser' => true,
1751+
'message' => 'Failed to create object because the class misses the "bar" property.',
1752+
],
1753+
[
1754+
'currentType' => 'string',
1755+
'expectedTypes' => ['string'],
1756+
'path' => 'date',
1757+
'useMessageForUser' => true,
1758+
'message' => 'The data is either not an string, an empty string, or null; you should pass a string that can be parsed with the passed format or a valid DateTime string.',
1759+
],
1760+
];
1761+
1762+
$this->assertSame($expected, $exceptionsAsArray);
1763+
}
1764+
}
17171765
}
17181766

17191767
class Model
@@ -1780,6 +1828,15 @@ public function __construct($value)
17801828
}
17811829
}
17821830

1831+
class DummyEntityWithStringAndDateTime
1832+
{
1833+
public function __construct(
1834+
public string $bar,
1835+
public \DateTimeInterface $date,
1836+
) {
1837+
}
1838+
}
1839+
17831840
class DummyUnionType
17841841
{
17851842
/**

0 commit comments

Comments
 (0)