Changeset 1389
- Timestamp:
- 02/29/08 15:57:54 (3 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotation.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMethodsAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLPropertiesAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/xml/serializer/matcher/stubXMLSerializerMethodPropertyMatcher.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php (modified) (10 diffs)
- trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializerObjectData.php (added)
- trunk/src/test/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotationTestCase.php (modified) (6 diffs)
- trunk/src/test/php/net/stubbles/xml/serializer/stubXMLSerializerTestCase.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotation.php
r1311 r1389 48 48 * 49 49 * @param stubReflectionProperty $property 50 * @param mixed $propertyValue51 50 * @return string|false 52 51 * @throws stubXMLException 53 52 */ 54 public function getTagnameForProperty(stubReflectionProperty $property , $propertyValue)53 public function getTagnameForProperty(stubReflectionProperty $property) 55 54 { 56 55 $matches = array(); … … 75 74 * 76 75 * @param stubReflectionMethod $method 77 * @param mixed $returnValue78 76 * @return string|bool 79 77 * @throws stubXMLException 80 78 */ 81 public function getTagnameForMethod(stubReflectionMethod $method , $returnValue)79 public function getTagnameForMethod(stubReflectionMethod $method) 82 80 { 83 81 $matches = array(); trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLMethodsAnnotation.php
r1276 r1389 24 24 * 25 25 * @param stubReflectionMethod $method 26 * @param mixed $returnValue27 26 * @return string|false 28 27 */ 29 public function getTagnameForMethod(stubReflectionMethod $method , $returnValue);28 public function getTagnameForMethod(stubReflectionMethod $method); 30 29 } 31 30 ?> trunk/src/main/php/net/stubbles/xml/serializer/annotations/stubXMLPropertiesAnnotation.php
r1229 r1389 24 24 * 25 25 * @param stubReflectionProperty $property 26 * @param mixed $propertyValue27 26 * @return string|false 28 27 */ 29 public function getTagnameForProperty(stubReflectionProperty $property , $propertyValue);28 public function getTagnameForProperty(stubReflectionProperty $property); 30 29 } 31 30 ?> trunk/src/main/php/net/stubbles/xml/serializer/matcher/stubXMLSerializerMethodPropertyMatcher.php
r1385 r1389 26 26 public function matchesMethod(ReflectionMethod $method) 27 27 { 28 if ($method->isPublic() === false ) {28 if ($method->isPublic() === false || $method->isStatic() === true) { 29 29 return false; 30 30 } … … 64 64 public function matchesProperty(ReflectionProperty $property) 65 65 { 66 return $property->isPublic(); 66 if ($property->isPublic() === false || $property->isStatic() === true) { 67 return false; 68 } 69 70 return true; 67 71 } 68 72 trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php
r1385 r1389 4 4 * 5 5 * @author Stephan Schmidt <schst@stubbles.net> 6 * @author Frank Kleine <mikey@stubbles.net> 6 7 * @package stubbles 7 8 * @subpackage xml_serializer 8 9 */ 9 stubClassLoader::load('net::stubbles::xml::serializer::annotations::stubXMLTagAnnotation', 10 'net::stubbles::xml::serializer::annotations::stubXMLFragmentAnnotation', 11 'net::stubbles::xml::serializer::annotations::stubXMLAttributeAnnotation', 12 'net::stubbles::xml::serializer::annotations::stubXMLIgnoreAnnotation', 13 'net::stubbles::xml::serializer::annotations::stubXMLPropertiesAnnotation', 14 'net::stubbles::xml::serializer::annotations::stubXMLMethodsAnnotation', 15 'net::stubbles::xml::serializer::annotations::stubXMLMatcherAnnotation', 16 'net::stubbles::xml::serializer::annotations::stubXMLStrategyAnnotation', 17 'net::stubbles::xml::serializer::matcher::stubXMLSerializerMethodPropertyMatcher', 18 'net::stubbles::reflection::reflection' 10 stubClassLoader::load('net::stubbles::xml::stubXMLStreamWriter', 11 'net::stubbles::xml::serializer::stubXMLSerializerObjectData' 19 12 ); 20 13 /** … … 35 28 const OPT_STRATEGY = 'strategy'; 36 29 /** 37 * Option to define the strategy38 */39 const OPT_STATIC = 'static';40 /**41 30 * Do not export any properties or methods 42 31 */ … … 60 49 */ 61 50 private $defaultOpts = array(self::OPT_ROOT_TAG => null, 62 self::OPT_STRATEGY => self::STRATEGY_ALL, 63 self::OPT_STATIC => false 51 self::OPT_STRATEGY => self::STRATEGY_ALL 64 52 ); 65 53 /** … … 69 57 */ 70 58 private $opts; 71 /** 72 * the matcher to be used for methods and properties 73 * 74 * @var stubXMLSerializerMethodPropertyMatcher 75 */ 76 protected $methodAndPropertyMatcher; 77 78 /** 79 * constructor 80 */ 81 public function __construct() 82 { 83 $this->methodAndPropertyMatcher = new stubXMLSerializerMethodPropertyMatcher(); 84 } 85 86 /** 87 * Serialize any data structure to XML 88 * 89 * @param mixed $data The data to serialize 90 * @param stubXMLStreamWriter $xmlWriter The XML Writer to use 59 60 /** 61 * serialize any data structure to XML 62 * 63 * @param mixed $data data to serialize 64 * @param stubXMLStreamWriter $xmlWriter XML Writer to use 91 65 * @param array $opts Options to influence the serializing 92 66 */ 93 public function serialize($data, stubXMLStreamWriter $xmlWriter, $opts = array())67 public function serialize($data, stubXMLStreamWriter $xmlWriter, array $opts = array()) 94 68 { 95 69 // set the currently used options … … 99 73 100 74 /** 101 * Serialize any data structure to XML102 * 103 * @param mixed $data Thedata to serialize104 * @param stubXMLStreamWriter $xmlWriter TheXML Writer to use105 * @param string $tagName Thename of the XML tag75 * serialize any data structure to XML 76 * 77 * @param mixed $data data to serialize 78 * @param stubXMLStreamWriter $xmlWriter XML Writer to use 79 * @param string $tagName name of the XML tag 106 80 */ 107 81 protected function serializeDispatcher($data, stubXMLStreamWriter $xmlWriter, $tagName = null) … … 109 83 switch (gettype($data)) { 110 84 case 'NULL': 111 if ( $tagName === null) {85 if (null === $tagName) { 112 86 $tagName = 'null'; 113 87 } … … 120 94 121 95 case 'boolean': 122 if ( $tagName === null) {96 if (null === $tagName) { 123 97 $tagName = 'boolean'; 124 98 } … … 132 106 case 'integer': 133 107 case 'double': 134 if ( $tagName === null) {108 if (null === $tagName) { 135 109 $tagName = gettype($data); 136 110 } … … 150 124 151 125 default: 152 // do not serialize other data types as they can not be serialized 153 } 154 } 155 156 /** 157 * Serialize an object 158 * 159 * @param object $object 160 * @param stubXMLStreamWriter $xmlWriter 161 * @param string $tagName 162 * @todo Refactor this method into smaller methods for improved readability 126 // nothing to do 127 } 128 } 129 130 /** 131 * serialize an object 132 * 133 * @param object $object object to serialize 134 * @param stubXMLStreamWriter $xmlWriter XML Writer to use 135 * @param string $tagName name of the XML tag 163 136 */ 164 137 protected function serializeObject($object, stubXMLStreamWriter $xmlWriter, $tagName) 165 138 { 166 $clazz = new stubReflectionClass(get_class($object)); 139 $serializerData = stubXMLSerializerObjectData::fromObject($object); 140 $xmlWriter->writeStartElement($serializerData->getTagName($tagName)); 141 $strategy = $serializerData->getStrategy($this->opts[self::OPT_STRATEGY]); 142 foreach ($serializerData->getProperties() as $propertyName => $propertyData) { 143 $this->handle($object->$propertyName, $xmlWriter, $propertyData, ($strategy & self::STRATEGY_PROPS)); 144 } 145 146 foreach ($serializerData->getMethods() as $methodName => $methodData) { 147 $this->handle($object->$methodName(), $xmlWriter, $methodData, ($strategy & self::STRATEGY_METHODS)); 148 } 149 150 $xmlWriter->writeEndElement(); 151 } 152 153 /** 154 * serializes given value with instructions from $data 155 * 156 * @param mixed $value the value to serialize 157 * @param stubXMLStreamWriter $xmlWriter XML Writer to use 158 * @param array<string,array<string,scalar>> $data instructions on how to serialize 159 * @param int $mustSerialize whether the element must be serialized or not 160 */ 161 protected function handle($value, stubXMLStreamWriter $xmlWriter, array $data, $mustSerialize) 162 { 163 switch ($data['type']) { 164 case 'attribute': 165 if ('' === (string) $value && true === $data['shouldSkipEmpty']) { 166 return; 167 } 168 169 $xmlWriter->writeAttribute($data['attributeName'], (string) $value); 170 break; 171 172 case 'fragment': 173 if (null != $data['tagName']) { 174 $xmlWriter->writeStartElement($data['tagName']); 175 $xmlWriter->writeXmlFragment($value); 176 $xmlWriter->writeEndElement(); 177 } else { 178 $xmlWriter->writeXmlFragment($value); 179 } 180 break; 181 182 default: 183 if (false === $data['mustSerialize'] && 0 === $mustSerialize) { 184 return; 185 } 186 187 if (is_array($value) === true) { 188 $this->serializeArray($value, $xmlWriter, $data['tagName'], $data['elementName']); 189 } else { 190 $this->serializeDispatcher($value, $xmlWriter, $data['tagName']); 191 } 192 } 193 } 194 195 /** 196 * serialize an array 197 * 198 * @param array $array array to serialize 199 * @param stubXMLStreamWriter $xmlWriter XML Writer to use 200 * @param string $tagName 'root' name for the array 201 * @param string $defaultTag The default tag for indexed arrays 202 */ 203 protected function serializeArray($array, stubXMLStreamWriter $xmlWriter, $tagName, $defaultTag = null) 204 { 167 205 if (null === $tagName) { 168 if ($clazz->hasAnnotation('XMLTag') === true) {169 $tagName = $clazz->getAnnotation('XMLTag')->getTagName();170 } else {171 $tagName = get_class($object);172 }173 }174 175 $xmlWriter->writeStartElement($tagName);176 if ($clazz->hasAnnotation('XMLStrategy')) {177 $strategy = $clazz->getAnnotation('XMLStrategy')->getValue();178 } else {179 $strategy = $this->opts[self::OPT_STRATEGY];180 }181 182 // export props183 $properties = $clazz->getPropertiesByMatcher($this->methodAndPropertyMatcher);184 $matcher = null;185 // get the property-matcher186 if ($clazz->hasAnnotation('XMLProperties')) {187 $matcher = $clazz->getAnnotation('XMLProperties');188 }189 190 foreach ($properties as $property) {191 $propValue = $property->getValue($object);192 if ($this->writeAnnotatedElement($property, $xmlWriter, $propValue) === true) {193 continue;194 }195 196 if ($property->hasAnnotation('XMLTag') === true) {197 $xmlTag = $property->getAnnotation('XMLTag');198 $tagName = $xmlTag->getTagName();199 $elementName = $xmlTag->getElementTagName();200 } else {201 if (null !== $matcher) {202 $tagName = $matcher->getTagnameForProperty($property, $propValue);203 if (false === $tagName) {204 continue;205 }206 } else {207 if (($strategy & self::STRATEGY_PROPS) === 0) {208 continue;209 }210 211 if ($this->opts[self::OPT_STATIC] === false && $property->isStatic() === true) {212 continue;213 }214 215 $tagName = $property->getName();216 }217 $elementName = null;218 }219 220 if (is_array($propValue) === true) {221 $this->serializeArray($propValue, $xmlWriter, $tagName, $elementName);222 } else {223 $this->serializeDispatcher($propValue, $xmlWriter, $tagName);224 }225 }226 227 // export methods228 $methods = $clazz->getMethodsByMatcher($this->methodAndPropertyMatcher);229 $matcher = null;230 // get the method-matcher231 if ($clazz->hasAnnotation('XMLMethods')) {232 $matcher = $clazz->getAnnotation('XMLMethods');233 }234 235 foreach ($methods as $method) {236 $returnValue = $method->invoke($object);237 if ($this->writeAnnotatedElement($method, $xmlWriter, $returnValue) === true) {238 continue;239 }240 241 if ($method->hasAnnotation('XMLTag') === true) {242 $xmlTag = $method->getAnnotation('XMLTag');243 $tagName = $xmlTag->getTagName();244 $elementName = $xmlTag->getElementTagName();245 } else {246 if (null !== $matcher) {247 $tagName = $matcher->getTagnameForMethod($method, $returnValue);248 if (false === $tagName) {249 continue;250 }251 } else {252 if (($strategy & self::STRATEGY_METHODS) === 0) {253 continue;254 }255 256 if ($this->opts[self::OPT_STATIC] === false && $method->isStatic() === true) {257 continue;258 }259 260 $tagName = $method->getName();261 }262 263 $elementName = null;264 }265 266 if (is_array($returnValue) === true) {267 $this->serializeArray($returnValue, $xmlWriter, $tagName, $elementName);268 } else {269 $this->serializeDispatcher($returnValue, $xmlWriter, $tagName);270 }271 }272 273 $xmlWriter->writeEndElement();274 }275 276 /**277 * serializes annotated element278 *279 * Returns true if element was serialized, else false.280 *281 * @param stubAnnotatable $annotatable the annotatable element to serialize282 * @param stubXMLStreamWriter $xmlWriter the xml writer to use283 * @param mixed $value the value to serialize284 * @return bool285 */286 protected function writeAnnotatedElement(stubAnnotatable $annotatable, stubXMLStreamWriter $xmlWriter, $value)287 {288 if ($annotatable->hasAnnotation('XMLAttribute') === true) {289 $xmlAttribute = $annotatable->getAnnotation('XMLAttribute');290 if ('' === (string) $value && $xmlAttribute->shouldSkipEmpty() === true) {291 return true;292 }293 294 $xmlWriter->writeAttribute($xmlAttribute->getAttributeName(), (string) $value);295 return true;296 } elseif ($annotatable->hasAnnotation('XMLFragment') === true) {297 $tagName = $annotatable->getAnnotation('XMLFragment')->getTagName();298 if (null != $tagName) {299 $xmlWriter->writeStartElement($tagName);300 $xmlWriter->writeXmlFragment($value);301 $xmlWriter->writeEndElement();302 } else {303 $xmlWriter->writeXmlFragment($value);304 }305 306 return true;307 }308 309 return false;310 }311 312 /**313 * Serialize an array314 *315 * @param array $array316 * @param stubXMLStreamWriter $xmlWriter317 * @param string $tagName The 'root' name for the array318 * @param string $defaultTag The default tag for indexed arrays319 */320 protected function serializeArray($array, stubXMLStreamWriter $xmlWriter, $tagName, $defaultTag = null)321 {322 if ($tagName === null) {323 206 $tagName = 'array'; 324 207 } 325 208 326 if ( $tagName !== false) {209 if (false !== $tagName) { 327 210 $xmlWriter->writeStartElement($tagName); 328 211 } 329 212 330 213 foreach ($array as $key => $value) { 331 if (is_int($key) ) {214 if (is_int($key) === true) { 332 215 if (null === $defaultTag) { 333 216 $this->serializeDispatcher($value, $xmlWriter); … … 340 223 } 341 224 342 if ( $tagName !== false) {225 if (false !== $tagName) { 343 226 $xmlWriter->writeEndElement(); 344 227 } trunk/src/test/php/net/stubbles/xml/serializer/annotations/stubXMLMatcherAnnotationTestCase.php
r1307 r1389 43 43 $matcher->setPattern('/.+/'); 44 44 45 $tagName = $matcher->getTagnameForProperty(new stubReflectionProperty('stubXMLMatcherAnnotationTestCase_Foo', 'bar') , 'foo');45 $tagName = $matcher->getTagnameForProperty(new stubReflectionProperty('stubXMLMatcherAnnotationTestCase_Foo', 'bar')); 46 46 $this->assertEquals('bar', $tagName); 47 47 } … … 57 57 $matcher->setPattern('/^get(.+)/'); 58 58 59 $tagName = $matcher->getTagnameForMethod(new stubReflectionMethod('stubXMLMatcherAnnotationTestCase_Foo', 'getBar') , 'foo');59 $tagName = $matcher->getTagnameForMethod(new stubReflectionMethod('stubXMLMatcherAnnotationTestCase_Foo', 'getBar')); 60 60 $this->assertEquals('bar', $tagName); 61 61 } … … 71 71 $matcher->setPattern('/^[0-9]+$/'); 72 72 73 $tagName = $matcher->getTagnameForProperty(new stubReflectionProperty('stubXMLMatcherAnnotationTestCase_Foo', 'bar') , 'foo');73 $tagName = $matcher->getTagnameForProperty(new stubReflectionProperty('stubXMLMatcherAnnotationTestCase_Foo', 'bar')); 74 74 $this->assertFalse($tagName); 75 75 } … … 85 85 $matcher->setPattern('/^getFoo/'); 86 86 87 $tagName = $matcher->getTagnameForMethod(new stubReflectionMethod('stubXMLMatcherAnnotationTestCase_Foo', 'getBar') , 'foo');87 $tagName = $matcher->getTagnameForMethod(new stubReflectionMethod('stubXMLMatcherAnnotationTestCase_Foo', 'getBar')); 88 88 $this->assertFalse($tagName); 89 89 } … … 100 100 $matcher->setPattern('/foo'); 101 101 102 @$matcher->getTagnameForProperty(new stubReflectionProperty('stubXMLMatcherAnnotationTestCase_Foo', 'bar') , 'foo');102 @$matcher->getTagnameForProperty(new stubReflectionProperty('stubXMLMatcherAnnotationTestCase_Foo', 'bar')); 103 103 } 104 104 … … 114 114 $matcher->setPattern('/foo'); 115 115 116 @$matcher->getTagnameFormethod(new stubReflectionMethod('stubXMLMatcherAnnotationTestCase_Foo', 'getBar') , 'foo');116 @$matcher->getTagnameFormethod(new stubReflectionMethod('stubXMLMatcherAnnotationTestCase_Foo', 'getBar')); 117 117 } 118 118 } trunk/src/test/php/net/stubbles/xml/serializer/stubXMLSerializerTestCase.php
r1271 r1389 279 279 $this->serializer->serialize(null, $writer, array(stubXMLSerializer::OPT_ROOT_TAG => 'root')); 280 280 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<root><null/></root>', $writer->asXML()); 281 $writer = new stubDomXMLStreamWriter(); 282 $this->serializer->serialize(null, $writer); 283 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<null><null/></null>', $writer->asXML()); 281 284 } 282 285 … … 327 330 $this->serializer->serialize(true, $writer, array(stubXMLSerializer::OPT_ROOT_TAG => 'root')); 328 331 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<root>true</root>', $writer->asXML()); 332 $writer = new stubDomXMLStreamWriter(); 333 $this->serializer->serialize(true, $writer); 334 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<boolean>true</boolean>', $writer->asXML()); 329 335 } 330 336 … … 336 342 public function assocArray() 337 343 { 338 $writer = new stubDomXMLStreamWriter(); 339 $array = array( 340 'one' => 'two', 341 'three' => 'four' 342 ); 344 $array = array('one' => 'two', 345 'three' => 'four' 346 ); 347 $writer = new stubDomXMLStreamWriter(); 343 348 $this->serializer->serialize($array, $writer, array(stubXMLSerializer::OPT_ROOT_TAG => 'root')); 344 349 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<root><one>two</one><three>four</three></root>', $writer->asXML()); 350 $writer = new stubDomXMLStreamWriter(); 351 $this->serializer->serialize($array, $writer); 352 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<array><one>two</one><three>four</three></array>', $writer->asXML()); 345 353 } 346 354 … … 352 360 public function indexedArray() 353 361 { 354 $ writer = new stubDomXMLStreamWriter();355 $ array = array('one', 'two', 'three');362 $array = array('one', 'two', 'three'); 363 $writer = new stubDomXMLStreamWriter(); 356 364 $this->serializer->serialize($array, $writer, array(stubXMLSerializer::OPT_ROOT_TAG => 'root')); 357 365 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<root><string>one</string><string>two</string><string>three</string></root>', $writer->asXML()); 366 $writer = new stubDomXMLStreamWriter(); 367 $this->serializer->serialize($array, $writer); 368 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<array><string>one</string><string>two</string><string>three</string></array>', $writer->asXML()); 358 369 } 359 370 … … 366 377 { 367 378 $writer = new stubDomXMLStreamWriter(); 368 $array = array( 369 'one' => 'two', 370 'three' => array('four' => 'five') 371 ); 379 $array = array('one' => 'two', 380 'three' => array('four' => 'five') 381 ); 372 382 $this->serializer->serialize($array, $writer, array(stubXMLSerializer::OPT_ROOT_TAG => 'root')); 373 383 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<root><one>two</one><three><four>five</four></three></root>', $writer->asXML()); … … 382 392 { 383 393 $writer = new stubDomXMLStreamWriter(); 384 $obj = new XMLSerializerFoo();394 $obj = new XMLSerializerFoo(); 385 395 $this->serializer->serialize($obj, $writer); 386 396 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<foo bar="test"><bar>42</bar></foo>', $writer->asXML()); … … 394 404 public function nestedObject() 395 405 { 396 $writer = new stubDomXMLStreamWriter();397 $obj = new XMLSerializerFoo();406 $writer = new stubDomXMLStreamWriter(); 407 $obj = new XMLSerializerFoo(); 398 408 $obj->bar = new XMLSerializerFoo(); 399 409 $this->serializer->serialize($obj, $writer); … … 414 424 415 425 $writer = new stubDomXMLStreamWriter(); 416 $obj = new XMLSerializerList2();426 $obj = new XMLSerializerList2(); 417 427 $this->serializer->serialize($obj, $writer); 418 428 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<container><item>one</item><item>two</item><item>three</item></container>', $writer->asXML()); … … 427 437 { 428 438 $writer = new stubDomXMLStreamWriter(); 429 $obj = new XMLSerializerMethods();439 $obj = new XMLSerializerMethods(); 430 440 $this->serializer->serialize($obj, $writer); 431 441 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<class method="returned"/>', $writer->asXML()); … … 440 450 { 441 451 $writer = new stubDomXMLStreamWriter(); 442 $obj = new XMLSerializerPropertyMatcher();452 $obj = new XMLSerializerPropertyMatcher(); 443 453 $this->serializer->serialize($obj, $writer); 444 454 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<testObject><one>one</one><two>two</two></testObject>', $writer->asXML()); … … 453 463 { 454 464 $writer = new stubDomXMLStreamWriter(); 455 $obj = new XMLSerializerMethodMatcher();465 $obj = new XMLSerializerMethodMatcher(); 456 466 $this->serializer->serialize($obj, $writer); 457 467 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<testObject><foo>foo</foo></testObject>', $writer->asXML()); … … 466 476 { 467 477 $writer = new stubDomXMLStreamWriter(); 468 $obj = new XMLSerializerFragmentTest();478 $obj = new XMLSerializerFragmentTest(); 469 479 $this->serializer->serialize($obj, $writer); 470 480 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<test><xml><foo>bar</foo></xml><foo>bar</foo></test>', $writer->asXML()); … … 479 489 { 480 490 $writer = new stubDomXMLStreamWriter(); 481 $obj = new XMLSerializerAttributeTest();491 $obj = new XMLSerializerAttributeTest(); 482 492 $this->serializer->serialize($obj, $writer); 483 493 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<test emptyProp2="" emptyMethod2=""/>', $writer->asXML()); … … 492 502 { 493 503 $writer = new stubDomXMLStreamWriter(); 494 $obj = new stubXMLSerializerTestCase_Static(); 495 $this->serializer->serialize($obj, $writer, array(stubXMLSerializer::OPT_STATIC => true)); 496 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<stubXMLSerializerTestCase_Static><foo>foo</foo><getBar>bar</getBar></stubXMLSerializerTestCase_Static>', $writer->asXML()); 497 498 $writer = new stubDomXMLStreamWriter(); 504 $obj = new stubXMLSerializerTestCase_Static(); 499 505 $this->serializer->serialize($obj, $writer); 500 506 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<stubXMLSerializerTestCase_Static/>', $writer->asXML()); … … 509 515 { 510 516 $writer = new stubDomXMLStreamWriter(); 511 $obj = new XMLSerializerUmlautTest();517 $obj = new XMLSerializerUmlautTest(); 512 518 $this->serializer->serialize($obj, $writer); 513 519 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . utf8_encode('<test bar="Hühnchen"><foo>Hähnchen</foo></test>'), $writer->asXML()); 514 520 } 521 522 /** 523 * a resource can not be serialized 524 * 525 * @test 526 */ 527 public function resource() 528 { 529 $writer = new stubDomXMLStreamWriter(); 530 $fp = fopen(__FILE__, 'rb'); 531 $this->serializer->serialize($fp, $writer); 532 $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>', $writer->asXML()); 533 fclose($fp); 534 } 535 536 /** 537 * object data container can only be created for objects 538 * 539 * @test 540 * @expectedException stubIllegalArgumentException 541 */ 542 public function objectDataConstructionOnlyForObjects() 543 { 544 $serializerData = new stubXMLSerializerObjectData('foo'); 545 } 546 547 /** 548 * object data container can only be created for objects 549 * 550 * @test 551 * @expectedException stubIllegalArgumentException 552 */ 553 public function objectDataOnlyForObjects() 554 { 555 $serializerData = stubXMLSerializerObjectData::fromObject('foo'); 556 } 515 557 } 516 558 ?>
