Skip to content

Commit f6dee97

Browse files
committed
handle case with throws from ArrayDenormalizer
1 parent c23a29b commit f6dee97

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/Symfony/Component/Serializer/Exception/InvalidArgumentException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
*
1717
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
1818
*/
19-
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
19+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface, AggregableExceptionInterface
2020
{
2121
}

src/Symfony/Component/Serializer/Tests/Fixtures/CollectErrorsDummy.php

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class CollectErrorsDummy
1919
*/
2020
public $arrayOfObjects;
2121

22+
/**
23+
* @var CollectErrorsArrayDummy[]
24+
*/
25+
public $stringArrayOfObjects;
26+
2227
/**
2328
* @var CollectErrorsObjectDummy
2429
*/

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,13 @@ public function testDeserializeAndUnwrap()
640640

641641
public function testCollectDenormalizationErrors()
642642
{
643-
$jsonData = '{"int":"string","array":"string","arrayOfObjects":[{"date":"string"}],"object":{"foo":"1","bar":"1"},"variadicObject":{"foo":1,"args":[{"foo":"1"},{"foo":"1","args":1}]}}';
643+
$jsonData = '{"int":"string","array":"string","arrayOfObjects":[{"date":"string"}],"stringArrayOfObjects":"string","object":{"foo":"1","bar":"1"},"variadicObject":{"foo":1,"args":[{"foo":"1"},{"foo":"1","args":1}]}}';
644644

645645
$expected = static function () {
646646
yield 'int' => 'The type of the "int" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\CollectErrorsDummy" must be one of "int" ("string" given).';
647647
yield 'array' => 'The type of the "array" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\CollectErrorsDummy" must be one of "array" ("string" given).';
648648
yield 'arrayOfObjects.date' => 'DateTimeImmutable::__construct(): Failed to parse time string (string) at position 0 (s): The timezone could not be found in the database';
649+
yield 'stringArrayOfObjects' => 'Data expected to be an array, string given.';
649650
yield 'object.foo' => 'The type of the "foo" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\CollectErrorsObjectDummy" must be one of "int" ("string" given).';
650651
yield 'object.bar' => 'The type of the "bar" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\CollectErrorsObjectDummy" must be one of "int" ("string" given).';
651652
yield 'object.baz' => 'Cannot create an instance of "Symfony\Component\Serializer\Tests\Fixtures\CollectErrorsObjectDummy" from serialized data because its constructor requires parameter "baz" to be present.';

0 commit comments

Comments
 (0)