[Serializer] Nicer ExtraAttributesException message for single attribute
This commit is contained in:
parent
2dcf313a87
commit
1ba6a2cf50
@ -22,7 +22,11 @@ class ExtraAttributesException extends RuntimeException
|
|||||||
|
|
||||||
public function __construct(array $extraAttributes, \Throwable $previous = null)
|
public function __construct(array $extraAttributes, \Throwable $previous = null)
|
||||||
{
|
{
|
||||||
$msg = sprintf('Extra attributes are not allowed ("%s" are unknown).', implode('", "', $extraAttributes));
|
$msg = sprintf(
|
||||||
|
'Extra attributes are not allowed ("%s" %s unknown).',
|
||||||
|
implode('", "', $extraAttributes),
|
||||||
|
\count($extraAttributes) > 1 ? 'are' : 'is'
|
||||||
|
);
|
||||||
|
|
||||||
$this->extraAttributes = $extraAttributes;
|
$this->extraAttributes = $extraAttributes;
|
||||||
|
|
||||||
|
@ -61,6 +61,20 @@ class AbstractObjectNormalizerTest extends TestCase
|
|||||||
$this->assertInstanceOf(Dummy::class, $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), []));
|
$this->assertInstanceOf(Dummy::class, $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), []));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDenormalizeWithExtraAttribute()
|
||||||
|
{
|
||||||
|
$this->expectException(ExtraAttributesException::class);
|
||||||
|
$this->expectExceptionMessage('Extra attributes are not allowed ("fooFoo" is unknown).');
|
||||||
|
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
|
||||||
|
$normalizer = new AbstractObjectNormalizerDummy($factory);
|
||||||
|
$normalizer->denormalize(
|
||||||
|
['fooFoo' => 'foo'],
|
||||||
|
Dummy::class,
|
||||||
|
'any',
|
||||||
|
['allow_extra_attributes' => false]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDenormalizeWithExtraAttributes()
|
public function testDenormalizeWithExtraAttributes()
|
||||||
{
|
{
|
||||||
$this->expectException(ExtraAttributesException::class);
|
$this->expectException(ExtraAttributesException::class);
|
||||||
|
Reference in New Issue
Block a user