cvs: pear /XML_Serializer/tests Unserializer_Arrays_TestCase.php Unserializer_Objects_TestCase.php run-tests.php

From: Date: Wed, 30 Nov 2005 19:45:52 +0000
Subject: cvs: pear /XML_Serializer/tests Unserializer_Arrays_TestCase.php Unserializer_Objects_TestCase.php run-tests.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-36628@lists.php.net to get a copy of this message
schst Wed Nov 30 14:45:52 2005 EDT Added files: /pear/XML_Serializer/tests Unserializer_Arrays_TestCase.php Unserializer_Objects_TestCase.php Modified files: /pear/XML_Serializer/tests run-tests.php Log: Added testcases for unserializing arrays and objects http://cvs.php.net/diff.php/pear/XML_Serializer/tests/run-tests.php?r1=1.9&r2=1.10&ty=u Index: pear/XML_Serializer/tests/run-tests.php diff -u pear/XML_Serializer/tests/run-tests.php:1.9 pear/XML_Serializer/tests/run-tests.php:1.10 --- pear/XML_Serializer/tests/run-tests.php:1.9 Wed Nov 30 14:34:51 2005 +++ pear/XML_Serializer/tests/run-tests.php Wed Nov 30 14:45:51 2005 @@ -2,7 +2,7 @@ /** * Unit tests for XML_Serializer package * - * $Id: run-tests.php,v 1.9 2005/11/30 19:34:51 schst Exp $ + * $Id: run-tests.php,v 1.10 2005/11/30 19:45:51 schst Exp $ * * @package XML_Serializer * @subpackage Tests @@ -37,6 +37,8 @@ 'Serializer_Option_Mode_TestCase', 'Unserializer_Scalars_TestCase', + 'Unserializer_Arrays_TestCase', + 'Unserializer_Objects_TestCase', 'Unserializer_Option_GuessTypes_TestCase' ); http://cvs.php.net/co.php/pear/XML_Serializer/tests/Unserializer_Arrays_TestCase.php?r=1.1&p=1 Index: pear/XML_Serializer/tests/Unserializer_Arrays_TestCase.php +++ pear/XML_Serializer/tests/Unserializer_Arrays_TestCase.php <?php /** * Testcase for unserializing XML to arrays * * @author Stephan Schmidt <schst@php-tools.net> * @package XML_Serializer * @subpackage Tests */ class Unserializer_Arrays_TestCase extends PHPUnit_TestCase { function Serializer_Scalars_TestCase($name) { $this->PHPUnit_TestCase($name); } /** * Test unserializing a simple array */ function testAssoc() { $u = new XML_Unserializer(); $u->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'array'); $xml = '<xml><foo>bar</foo></xml>'; $u->unserialize($xml); $this->assertEquals(array('foo' => 'bar'), $u->getUnserializedData()); } /** * Test unserializing an indexed array */ function testIndexed() { $u = new XML_Unserializer(); $u->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'array'); $xml = '<xml><foo>bar</foo><foo>tomato</foo></xml>'; $u->unserialize($xml); $this->assertEquals(array('foo' => array('bar', 'tomato')), $u->getUnserializedData()); } } http://cvs.php.net/co.php/pear/XML_Serializer/tests/Unserializer_Objects_TestCase.php?r=1.1&p=1 Index: pear/XML_Serializer/tests/Unserializer_Objects_TestCase.php +++ pear/XML_Serializer/tests/Unserializer_Objects_TestCase.php <?php /** * Testcase for unserializing XML to objects * * @author Stephan Schmidt <schst@php-tools.net> * @package XML_Serializer * @subpackage Tests */ class Unserializer_Objects_TestCase extends PHPUnit_TestCase { function Serializer_Scalars_TestCase($name) { $this->PHPUnit_TestCase($name); } /** * Test unserializing to a stdClass object */ function testStdClass() { $u = new XML_Unserializer(); $u->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'object'); $xml = '<xml><foo>bar</foo></xml>'; $u->unserialize($xml); $result = new stdClass(); $result->foo = 'bar'; $this->assertEquals($result, $u->getUnserializedData()); } /** * Test unserializing to a custom class */ function testDefaultClass() { $u = new XML_Unserializer(); $u->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'object'); $u->setOption(XML_UNSERIALIZER_OPTION_DEFAULT_CLASS, 'Foo'); $xml = '<xml><foo>bar</foo></xml>'; $u->unserialize($xml); $result = new Foo(); $result->foo = 'bar'; $this->assertEquals($result, $u->getUnserializedData()); } /** * Test unserializing to a class based on the tag name */ function testTagnameAsClass() { $u = new XML_Unserializer(); $u->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'object'); $u->setOption(XML_UNSERIALIZER_OPTION_DEFAULT_CLASS, 'Foo'); $xml = '<foo><bar><boo>tomato</boo></bar></foo>'; $u->unserialize($xml); $result = new Foo(); $result->bar = new Bar(); $result->bar->boo = 'tomato'; $this->assertEquals($result, $u->getUnserializedData()); } /** * Test unserializing with a setter method */ function testSetterMethod() { $u = new XML_Unserializer(); $u->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'object'); $u->setOption(XML_UNSERIALIZER_OPTION_DEFAULT_CLASS, 'Foo'); $xml = '<SetterExample><foo>tomato</foo></SetterExample>'; $u->unserialize($xml); $result = new SetterExample(); $result->setFoo('tomato'); $this->assertEquals($result, $u->getUnserializedData()); } } class Foo { } class Bar { } class SetterExample { var $_hidden = null; function setFoo($foo) { $this->_hidden = $foo; } } ?>

« previous php.pear.cvs (#36628) next »