|
14 | 14 | use Doctrine\Common\Annotations\AnnotationReader; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | 16 | use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; |
| 17 | +use Symfony\Component\Serializer\Encoder\CsvEncoder; |
17 | 18 | use Symfony\Component\Serializer\Encoder\JsonEncoder; |
| 19 | +use Symfony\Component\Serializer\Encoder\XmlEncoder; |
| 20 | +use Symfony\Component\Serializer\Encoder\YamlEncoder; |
18 | 21 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; |
19 | 22 | use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; |
20 | 23 | use Symfony\Component\Serializer\Mapping\ClassMetadata; |
@@ -182,6 +185,48 @@ public function testSerializeArrayOfScalars() |
182 | 185 | $this->assertEquals(json_encode($data), $result); |
183 | 186 | } |
184 | 187 |
|
| 188 | + public function testSerializeEmpty() |
| 189 | + { |
| 190 | + $serializer = new Serializer(array(new ObjectNormalizer()), array('json' => new JsonEncoder())); |
| 191 | + $data = array('foo' => new \stdClass()); |
| 192 | + $result = $serializer->serialize($data, 'json'); |
| 193 | + $this->assertEquals('{"foo":{}}', $result); |
| 194 | + } |
| 195 | + |
| 196 | + public function testSerializeEmptyYaml() |
| 197 | + { |
| 198 | + $serializer = new Serializer(array(new ObjectNormalizer()), array('yaml' => new YamlEncoder())); |
| 199 | + $data = array('foo' => new \stdClass()); |
| 200 | + $result = $serializer->serialize($data, 'yaml'); |
| 201 | + $this->assertEquals('{ foo: null }', $result); |
| 202 | + } |
| 203 | + |
| 204 | + public function testSerializeEmptyXml() |
| 205 | + { |
| 206 | + $serializer = new Serializer(array(new ObjectNormalizer()), array('xml' => new XmlEncoder())); |
| 207 | + $data = array('foo' => new \stdClass()); |
| 208 | + $result = $serializer->serialize($data, 'xml'); |
| 209 | + $this->assertEquals(<<<'XML' |
| 210 | +<?xml version="1.0"?> |
| 211 | +<response><foo/></response> |
| 212 | + |
| 213 | +XML |
| 214 | + , $result); |
| 215 | + } |
| 216 | + |
| 217 | + public function testSerializeEmptyCsv() |
| 218 | + { |
| 219 | + $serializer = new Serializer(array(new ObjectNormalizer()), array('csv' => new CsvEncoder())); |
| 220 | + $data = array('foo' => new \stdClass(), 'bar' => new \stdClass()); |
| 221 | + $result = $serializer->serialize($data, 'csv'); |
| 222 | + $this->assertEquals(<<<'CSV' |
| 223 | +foo,bar |
| 224 | +, |
| 225 | + |
| 226 | +CSV |
| 227 | +, $result); |
| 228 | + } |
| 229 | + |
185 | 230 | /** |
186 | 231 | * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException |
187 | 232 | */ |
|
0 commit comments