platform/api/symfony/Component/Serializer/Tests/DeserializeNestedArrayOfObjectsTest.yaml

145 lines
7.7 KiB
YAML
Raw Normal View History

2024-09-02 17:44:11 +00:00
name: DeserializeNestedArrayOfObjectsTest
class_comment: null
dependencies:
- name: TestCase
type: class
source: PHPUnit\Framework\TestCase
- name: PhpDocExtractor
type: class
source: Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor
- name: JsonEncoder
type: class
source: Symfony\Component\Serializer\Encoder\JsonEncoder
- name: ArrayDenormalizer
type: class
source: Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
- name: ObjectNormalizer
type: class
source: Symfony\Component\Serializer\Normalizer\ObjectNormalizer
- name: Serializer
type: class
source: Symfony\Component\Serializer\Serializer
properties:
- name: animals
visibility: private
comment: "# * @dataProvider provider\n# */\n# public function testPropertyPhpDoc($class)\n\
# {\n# $json = <<<EOF\n# {\n# \"animals\": [\n# {\"name\": \"Bug\"}\n# ]\n# }\n\
# EOF;\n# $serializer = new Serializer([\n# new ObjectNormalizer(null, null, null,\
\ new PhpDocExtractor()),\n# new ArrayDenormalizer(),\n# ], ['json' => new JsonEncoder()]);\n\
# \n# /** @var Zoo|ZooImmutable $zoo */\n# $zoo = $serializer->deserialize($json,\
\ $class, 'json');\n# \n# self::assertCount(1, $zoo->getAnimals());\n# self::assertInstanceOf(Animal::class,\
\ $zoo->getAnimals()[0]);\n# }\n# \n# public function testPropertyPhpDocWithKeyTypes()\n\
# {\n# $json = <<<EOF\n# {\n# \"animalsInt\": [\n# {\"name\": \"Bug\"}\n# ],\n\
# \"animalsString\": {\n# \"animal1\": {\"name\": \"Bug\"}\n# },\n# \"animalsUnion\"\
: {\n# \"animal2\": {\"name\": \"Bug\"},\n# \"2\": {\"name\": \"Dog\"}\n# },\n\
# \"animalsGenerics\": {\n# \"animal3\": {\"name\": \"Bug\"},\n# \"3\": {\"name\"\
: \"Dog\"}\n# }\n# }\n# EOF;\n# $serializer = new Serializer([\n# new ObjectNormalizer(null,\
\ null, null, new PhpDocExtractor()),\n# new ArrayDenormalizer(),\n# ], ['json'\
\ => new JsonEncoder()]);\n# \n# /** @var ZooWithKeyTypes $zoo */\n# $zoo = $serializer->deserialize($json,\
\ ZooWithKeyTypes::class, 'json');\n# \n# self::assertCount(1, $zoo->animalsInt);\n\
# self::assertArrayHasKey(0, $zoo->animalsInt);\n# self::assertInstanceOf(Animal::class,\
\ $zoo->animalsInt[0]);\n# \n# self::assertCount(1, $zoo->animalsString);\n# self::assertArrayHasKey('animal1',\
\ $zoo->animalsString);\n# self::assertInstanceOf(Animal::class, $zoo->animalsString['animal1']);\n\
# \n# self::assertCount(2, $zoo->animalsUnion);\n# self::assertArrayHasKey('animal2',\
\ $zoo->animalsUnion);\n# self::assertInstanceOf(Animal::class, $zoo->animalsUnion['animal2']);\n\
# self::assertArrayHasKey(2, $zoo->animalsUnion);\n# self::assertInstanceOf(Animal::class,\
\ $zoo->animalsUnion[2]);\n# \n# self::assertCount(2, $zoo->animalsGenerics);\n\
# self::assertArrayHasKey('animal3', $zoo->animalsGenerics);\n# self::assertInstanceOf(Animal::class,\
\ $zoo->animalsGenerics['animal3']);\n# self::assertArrayHasKey(3, $zoo->animalsGenerics);\n\
# self::assertInstanceOf(Animal::class, $zoo->animalsGenerics[3]);\n# }\n# }\n\
# \n# class Zoo\n# {\n# /** @var Animal[]"
- name: animals
visibility: private
comment: "# * @return Animal[]\n# */\n# public function getAnimals(): array\n# {\n\
# return $this->animals;\n# }\n# \n# /**\n# * @param Animal[] $animals\n# */\n\
# public function setAnimals(array $animals)\n# {\n# $this->animals = $animals;\n\
# }\n# }\n# \n# class ZooImmutable\n# {\n# /** @var Animal[]"
- name: animalsInt
visibility: public
comment: "# * @param Animal[] $animals\n# */\n# public function __construct(array\
\ $animals = [])\n# {\n# $this->animals = $animals;\n# }\n# \n# /**\n# * @return\
\ Animal[]\n# */\n# public function getAnimals(): array\n# {\n# return $this->animals;\n\
# }\n# }\n# \n# class ZooWithKeyTypes\n# {\n# /** @var array<int, Animal>"
- name: animalsString
visibility: public
comment: '# @var array<string, Animal>'
- name: animalsUnion
visibility: public
comment: '# @var array<int|string, Animal>'
- name: animalsGenerics
visibility: public
comment: '# @var \Traversable<Animal>'
- name: name
visibility: private
comment: '# @var string'
methods:
- name: provider
visibility: public
parameters: []
comment: null
- name: testPropertyPhpDoc
visibility: public
parameters:
- name: class
comment: '# * @dataProvider provider'
- name: getAnimals
visibility: public
parameters: []
comment: "# @var Zoo|ZooImmutable $zoo */\n# $zoo = $serializer->deserialize($json,\
\ $class, 'json');\n# \n# self::assertCount(1, $zoo->getAnimals());\n# self::assertInstanceOf(Animal::class,\
\ $zoo->getAnimals()[0]);\n# }\n# \n# public function testPropertyPhpDocWithKeyTypes()\n\
# {\n# $json = <<<EOF\n# {\n# \"animalsInt\": [\n# {\"name\": \"Bug\"}\n# ],\n\
# \"animalsString\": {\n# \"animal1\": {\"name\": \"Bug\"}\n# },\n# \"animalsUnion\"\
: {\n# \"animal2\": {\"name\": \"Bug\"},\n# \"2\": {\"name\": \"Dog\"}\n# },\n\
# \"animalsGenerics\": {\n# \"animal3\": {\"name\": \"Bug\"},\n# \"3\": {\"name\"\
: \"Dog\"}\n# }\n# }\n# EOF;\n# $serializer = new Serializer([\n# new ObjectNormalizer(null,\
\ null, null, new PhpDocExtractor()),\n# new ArrayDenormalizer(),\n# ], ['json'\
\ => new JsonEncoder()]);\n# \n# /** @var ZooWithKeyTypes $zoo */\n# $zoo = $serializer->deserialize($json,\
\ ZooWithKeyTypes::class, 'json');\n# \n# self::assertCount(1, $zoo->animalsInt);\n\
# self::assertArrayHasKey(0, $zoo->animalsInt);\n# self::assertInstanceOf(Animal::class,\
\ $zoo->animalsInt[0]);\n# \n# self::assertCount(1, $zoo->animalsString);\n# self::assertArrayHasKey('animal1',\
\ $zoo->animalsString);\n# self::assertInstanceOf(Animal::class, $zoo->animalsString['animal1']);\n\
# \n# self::assertCount(2, $zoo->animalsUnion);\n# self::assertArrayHasKey('animal2',\
\ $zoo->animalsUnion);\n# self::assertInstanceOf(Animal::class, $zoo->animalsUnion['animal2']);\n\
# self::assertArrayHasKey(2, $zoo->animalsUnion);\n# self::assertInstanceOf(Animal::class,\
\ $zoo->animalsUnion[2]);\n# \n# self::assertCount(2, $zoo->animalsGenerics);\n\
# self::assertArrayHasKey('animal3', $zoo->animalsGenerics);\n# self::assertInstanceOf(Animal::class,\
\ $zoo->animalsGenerics['animal3']);\n# self::assertArrayHasKey(3, $zoo->animalsGenerics);\n\
# self::assertInstanceOf(Animal::class, $zoo->animalsGenerics[3]);\n# }\n# }\n\
# \n# class Zoo\n# {\n# /** @var Animal[] */\n# private $animals = [];\n# \n#\
\ /**\n# * @return Animal[]"
- name: setAnimals
visibility: public
parameters:
- name: animals
comment: '# * @param Animal[] $animals'
- name: __construct
visibility: public
parameters:
- name: animals
default: '[]'
comment: "# @var Animal[] */\n# private $animals = [];\n# \n# /**\n# * @param Animal[]\
\ $animals"
- name: getAnimals
visibility: public
parameters: []
comment: '# * @return Animal[]'
- name: setName
visibility: public
parameters:
- name: name
comment: "# @var array<int, Animal> */\n# public $animalsInt = [];\n# /** @var array<string,\
\ Animal> */\n# public $animalsString = [];\n# /** @var array<int|string, Animal>\
\ */\n# public $animalsUnion = [];\n# /** @var \\Traversable<Animal> */\n# public\
\ $animalsGenerics = [];\n# }\n# \n# class Animal\n# {\n# /** @var string */\n\
# private $name;\n# \n# public function getName(): ?string\n# {\n# return $this->name;\n\
# }\n# \n# /**\n# * @param string|null $name"
traits:
- PHPUnit\Framework\TestCase
- Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor
- Symfony\Component\Serializer\Encoder\JsonEncoder
- Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
- Symfony\Component\Serializer\Normalizer\ObjectNormalizer
- Symfony\Component\Serializer\Serializer
interfaces: []