* @author Chuck Burgess */ require_once 'XML/Serializer.php'; /** * Unit Tests for serializing arrays * * @package XML_Serializer * @subpackage tests * @author Stephan Schmidt * @author Chuck Burgess */ class XML_Serializer_Objects_TestCase extends PHPUnit_Framework_TestCase { private $options = array( XML_SERIALIZER_OPTION_INDENT => '', XML_SERIALIZER_OPTION_LINEBREAKS => '', ); /** * Test serializing an object without any properties */ public function testEmptyObject() { $s = new XML_Serializer($this->options); $s->serialize(new stdClass()); $this->assertEquals('', $s->getSerializedData()); } /** * Test serializing a simple object */ public function testSimpleObject() { $obj = new stdClass(); $obj->foo = 'bar'; $s = new XML_Serializer($this->options); $s->serialize($obj); $this->assertEquals('bar', $s->getSerializedData()); } /** * Test serializing a nested object */ public function testNestedObject() { $obj = new stdClass(); $obj->foo = new stdClass(); $obj->foo->bar = 'nested'; $s = new XML_Serializer($this->options); $s->serialize($obj); $this->assertEquals('nested', $s->getSerializedData()); } /** * Test serializing an object, that supports __sleep */ public function testSleep() { $obj = new MyClass('foo', 'bar'); $s = new XML_Serializer($this->options); $s->serialize($obj); $this->assertEquals('foo', $s->getSerializedData()); } } class MyClass { var $foo; var $bar; public function __construct($foo, $bar) { $this->foo = $foo; $this->bar = $bar; } public function __sleep() { return array('foo'); } } ?>