From e9cb21f9472158b956bd97ea0de66b874753b2c5 Mon Sep 17 00:00:00 2001 From: karser Date: Sat, 8 Dec 2018 00:48:57 +0200 Subject: [PATCH] [Serializer] Added the initial reproducer of #28825 --- .../DeserializeNestedArrayOfObjectsTest.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/Symfony/Component/Serializer/Tests/DeserializeNestedArrayOfObjectsTest.php diff --git a/src/Symfony/Component/Serializer/Tests/DeserializeNestedArrayOfObjectsTest.php b/src/Symfony/Component/Serializer/Tests/DeserializeNestedArrayOfObjectsTest.php new file mode 100644 index 000000000000..293e5e46834b --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/DeserializeNestedArrayOfObjectsTest.php @@ -0,0 +1,103 @@ + new JsonEncoder())); + //WHEN + /** @var Zoo $zoo */ + $zoo = $serializer->deserialize($json, $class, 'json'); + //THEN + self::assertCount(1, $zoo->getAnimals()); + self::assertInstanceOf(Animal::class, $zoo->getAnimals()[0]); + } +} + +class Zoo { + /** @var Animal[] */ + private $animals = []; + /** + * @return Animal[] + */ + public function getAnimals(): array + { + return $this->animals; + } + /** + * @param Animal[] $animals + */ + public function setAnimals(array $animals): void + { + $this->animals = $animals; + } +} + +class ZooImmutable { + /** @var Animal[] */ + private $animals = []; + /** + * @param Animal[] $animals + */ + public function __construct(array $animals = []) + { + $this->animals = $animals; + } + /** + * @return Animal[] + */ + public function getAnimals(): array + { + return $this->animals; + } +} + +class Animal { + /** @var string */ + private $name; + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + /** + * @param string $name + */ + public function setName(?string $name): void + { + $this->name = $name; + } +}