* @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_Scalars_TestCase extends PHPUnit_Framework_TestCase { /** * Test serializing a string */ public function testString() { $s = new XML_Serializer(); $s->serialize('a string'); $this->assertEquals('a string', $s->getSerializedData()); $s->serialize(''); $this->assertEquals('', $s->getSerializedData()); } /** * Test serializing a integer */ public function testInteger() { $s = new XML_Serializer(); $s->serialize(456223); $this->assertEquals('456223', $s->getSerializedData()); $s->serialize(-34); $this->assertEquals('-34', $s->getSerializedData()); $s->serialize(0); $this->assertEquals('0', $s->getSerializedData()); } /** * Test serializing a float */ public function testDouble() { $s = new XML_Serializer(); $s->serialize(455.65); $this->assertEquals('455.65', $s->getSerializedData()); $s->serialize(-1.65451); $this->assertEquals('-1.65451', $s->getSerializedData()); } /** * Test serializing a boolean */ public function testBoolean() { $s = new XML_Serializer(); $s->serialize(true); $this->assertEquals('1', $s->getSerializedData()); $s->serialize(false); $this->assertEquals('', $s->getSerializedData()); } /** * Test serializing a null value */ public function testNull() { $s = new XML_Serializer(); $s->serialize(null); $this->assertEquals('', $s->getSerializedData()); } /** * Test serializing a resource */ public function testResource() { $s = new XML_Serializer(); $s->serialize(fopen(__FILE__, 'r')); $this->assertRegExp('/Resource id #[0-9]+<\/resource>/', $s->getSerializedData()); } } ?>