Browse Source

test for serializing null

mattw 12 years ago
parent
commit
b01a091bb5

+ 1 - 1
Serializer/XmlSerializationVisitor.php

@@ -76,7 +76,7 @@ class XmlSerializationVisitor extends AbstractVisitor
             $this->document = $this->createDocument(null, null, true);
             $node = $this->document->createAttribute('xsi:nil');
             $node->value = 'true';
-            $this->currentNode->appendChild($this->document->appendChild($node));
+            $this->currentNode->appendChild($node);
 
             return;
         }

+ 9 - 0
Tests/Serializer/BaseSerializationTest.php

@@ -124,6 +124,15 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($this->getContent('simple_object_nullable'), $serializer->serialize($obj, $this->getFormat()));
     }
 
+    public function testNull()
+    {
+        $this->assertEquals($this->getContent('null'), $this->serialize(null));
+
+        if ($this->hasDeserializer()) {
+            $this->assertEquals(null, $this->deserialize($this->getContent('null'), 'NULL'));
+        }
+    }
+
     public function testString()
     {
         $this->assertEquals($this->getContent('string'), $this->serialize('foo'));

+ 1 - 0
Tests/Serializer/JsonSerializationTest.php

@@ -82,6 +82,7 @@ class JsonSerializationTest extends BaseSerializationTest
             $outputs['virtual_properties_high'] = '{"high":8}';
             $outputs['virtual_properties_all'] = '{"low":1,"high":8}';
             $outputs['nullable'] = '{"foo":"bar","baz":null}';
+            $outputs['null'] = 'null';
             $outputs['simple_object_nullable'] = '{"foo":"foo","moo":"bar","camel_case":"boo","null_property":null}';
             $outputs['input'] = '{"attributes":{"type":"text","name":"firstname","value":"Adrien"}}';
             $outputs['hash_empty'] = '{"hash":{}}';

+ 2 - 0
Tests/Serializer/xml/null.xml

@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<result xsi:nil="true"/>

+ 1 - 0
Tests/Serializer/yml/null.yml

@@ -0,0 +1 @@
+null