Skip to content

Commit d84f0b7

Browse files
Merge branch '6.4' into 7.2
* 6.4: [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 [VarDumper] Avoid deprecated call in PgSqlCaster Fix command option mode (InputOption::VALUE_REQUIRED) [Uid] Improve entropy of the increment for UUIDv7
2 parents d35f516 + b40a697 commit d84f0b7

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-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/SerializerTest.php

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

17011701
$serializer->denormalize($data, DummyWithVariadicParameter::class);
17021702
}
1703+
1704+
public function testDenormalizationFailsWithMultipleErrorsInDefaultContext()
1705+
{
1706+
$serializer = new Serializer(
1707+
[new DateTimeNormalizer(), new ObjectNormalizer()],
1708+
[],
1709+
[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true]
1710+
);
1711+
1712+
$data = ['date' => '', 'unknown' => null];
1713+
1714+
try {
1715+
$serializer->denormalize($data, DummyEntityWithStringAndDateTime::class);
1716+
$this->fail('Expected PartialDenormalizationException was not thrown');
1717+
} catch (PartialDenormalizationException $e) {
1718+
$this->assertIsArray($e->getErrors());
1719+
$this->assertCount(2, $e->getErrors(), 'Expected two denormalization errors');
1720+
1721+
$exceptionsAsArray = array_map(function (NotNormalizableValueException $ex): array {
1722+
return [
1723+
'currentType' => $ex->getCurrentType(),
1724+
'expectedTypes' => $ex->getExpectedTypes(),
1725+
'path' => $ex->getPath(),
1726+
'useMessageForUser' => $ex->canUseMessageForUser(),
1727+
'message' => $ex->getMessage(),
1728+
];
1729+
}, $e->getErrors());
1730+
1731+
$expected = [
1732+
[
1733+
'currentType' => 'null',
1734+
'expectedTypes' => ['string'],
1735+
'path' => 'bar',
1736+
'useMessageForUser' => true,
1737+
'message' => 'Failed to create object because the class misses the "bar" property.',
1738+
],
1739+
[
1740+
'currentType' => 'string',
1741+
'expectedTypes' => ['string'],
1742+
'path' => 'date',
1743+
'useMessageForUser' => true,
1744+
'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.',
1745+
],
1746+
];
1747+
1748+
$this->assertSame($expected, $exceptionsAsArray);
1749+
}
1750+
}
17031751
}
17041752

17051753
class Model
@@ -1766,6 +1814,15 @@ public function __construct($value)
17661814
}
17671815
}
17681816

1817+
class DummyEntityWithStringAndDateTime
1818+
{
1819+
public function __construct(
1820+
public string $bar,
1821+
public \DateTimeInterface $date,
1822+
) {
1823+
}
1824+
}
1825+
17691826
class DummyUnionType
17701827
{
17711828
/**

0 commit comments

Comments
 (0)