|
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\MockObject\MockObject;
|
6 | 6 | use PHPUnit\Framework\TestCase;
|
| 7 | +use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; |
| 8 | +use Symfony\Component\Serializer\Encoder\JsonEncoder; |
7 | 9 | use Symfony\Component\Serializer\Mapping\AttributeMetadata;
|
8 | 10 | use Symfony\Component\Serializer\Mapping\ClassMetadata;
|
9 | 11 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
@@ -135,19 +137,49 @@ public function testObjectWithNullableConstructorArgument()
|
135 | 137 | }
|
136 | 138 |
|
137 | 139 | /**
|
| 140 | + * @dataProvider getNormalizer |
| 141 | + * |
138 | 142 | * @requires PHP 5.6
|
139 | 143 | */
|
140 |
| - public function testObjectWithVariadicConstructorTypedArguments() |
| 144 | + public function testObjectWithVariadicConstructorTypedArguments(AbstractNormalizer $normalizer) |
141 | 145 | {
|
142 |
| - $normalizer = new PropertyNormalizer(); |
143 |
| - $normalizer->setSerializer(new Serializer([$normalizer])); |
144 |
| - $data = ['foo' => [['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', 'qux' => 'Qux'], ['foo' => 'FOO', 'bar' => 'BAR', 'baz' => 'BAZ', 'qux' => 'QUX']]]; |
145 |
| - $dummy = $normalizer->denormalize($data, VariadicConstructorTypedArgsDummy::class); |
| 146 | + $d1 = new Dummy(); |
| 147 | + $d1->foo = 'Foo'; |
| 148 | + $d1->bar = 'Bar'; |
| 149 | + $d1->baz = 'Baz'; |
| 150 | + $d1->qux = 'Quz'; |
| 151 | + $d2 = new Dummy(); |
| 152 | + $d2->foo = 'FOO'; |
| 153 | + $d2->bar = 'BAR'; |
| 154 | + $d2->baz = 'BAZ'; |
| 155 | + $d2->qux = 'QUZ'; |
| 156 | + $obj = new VariadicConstructorTypedArgsDummy($d1, $d2); |
| 157 | + |
| 158 | + $serializer = new Serializer([$normalizer], [new JsonEncoder()]); |
| 159 | + $normalizer->setSerializer($serializer); |
| 160 | + $data = $serializer->serialize($obj, 'json'); |
| 161 | + $dummy = $normalizer->denormalize(json_decode($data, true), VariadicConstructorTypedArgsDummy::class); |
| 162 | + $this->assertInstanceOf(VariadicConstructorTypedArgsDummy::class, $dummy); |
| 163 | + $this->assertCount(2, $dummy->getFoo()); |
| 164 | + foreach ($dummy->getFoo() as $foo) { |
| 165 | + $this->assertInstanceOf(Dummy::class, $foo); |
| 166 | + } |
146 | 167 |
|
| 168 | + $dummy = $serializer->deserialize($data, VariadicConstructorTypedArgsDummy::class, 'json'); |
147 | 169 | $this->assertInstanceOf(VariadicConstructorTypedArgsDummy::class, $dummy);
|
148 | 170 | $this->assertCount(2, $dummy->getFoo());
|
149 | 171 | foreach ($dummy->getFoo() as $foo) {
|
150 | 172 | $this->assertInstanceOf(Dummy::class, $foo);
|
151 | 173 | }
|
152 | 174 | }
|
| 175 | + |
| 176 | + public function getNormalizer() |
| 177 | + { |
| 178 | + $extractor = new PhpDocExtractor(); |
| 179 | + |
| 180 | + yield [new PropertyNormalizer()]; |
| 181 | + yield [new PropertyNormalizer(null, null, $extractor)]; |
| 182 | + yield [new ObjectNormalizer()]; |
| 183 | + yield [new ObjectNormalizer(null, null, null, $extractor)]; |
| 184 | + } |
153 | 185 | }
|
0 commit comments