/**
  * @covers MicrosoftAzure\Storage\Queue\Models\QueueMessage::toXml
  */
 public function testToXml()
 {
     // Setup
     $queueMessage = new QueueMessage();
     $messageText = 'this is message text';
     $array = array('MessageText' => $messageText);
     $queueMessage->setMessageText($messageText);
     $xmlSerializer = new XmlSerializer();
     $properties = array(XmlSerializer::ROOT_NAME => QueueMessage::$xmlRootName);
     $expected = $xmlSerializer->serialize($array, $properties);
     // Test
     $actual = $queueMessage->toXml($xmlSerializer);
     // Assert
     $this->assertEquals($expected, $actual);
 }
Esempio n. 2
0
 /** 
  * Serialize an object with specified root element name. 
  * 
  * @param object $targetObject The target object. 
  * @param string $rootName     The name of the root element. 
  * 
  * @return string
  */
 public static function objectSerialize($targetObject, $rootName)
 {
     Validate::notNull($targetObject, 'targetObject');
     Validate::isString($rootName, 'rootName');
     $xmlWriter = new \XmlWriter();
     $xmlWriter->openMemory();
     $xmlWriter->setIndent(true);
     $reflectionClass = new \ReflectionClass($targetObject);
     $methodArray = $reflectionClass->getMethods();
     $attributes = self::_getInstanceAttributes($targetObject, $methodArray);
     $xmlWriter->startElement($rootName);
     if (!is_null($attributes)) {
         foreach (array_keys($attributes) as $attributeKey) {
             $xmlWriter->writeAttribute($attributeKey, $attributes[$attributeKey]);
         }
     }
     foreach ($methodArray as $method) {
         if (strpos($method->name, 'get') === 0 && $method->isPublic() && $method->name != 'getAttributes') {
             $variableName = substr($method->name, 3);
             $variableValue = $method->invoke($targetObject);
             if (!empty($variableValue)) {
                 if (gettype($variableValue) === 'object') {
                     $xmlWriter->writeRaw(XmlSerializer::objectSerialize($variableValue, $variableName));
                 } else {
                     $xmlWriter->writeElement($variableName, $variableValue);
                 }
             }
         }
     }
     $xmlWriter->endElement();
     return $xmlWriter->outputMemory(true);
 }
Esempio n. 3
0
 /**
  * Converts the  BlockList object to XML representation
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string
  */
 public function toXml($xmlSerializer)
 {
     $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName);
     $array = array();
     foreach ($this->_entries as $value) {
         $array[] = array($value->getType() => $value->getBlockId());
     }
     return $xmlSerializer->serialize($array, $properties);
 }
Esempio n. 4
0
 /**
  * Converts this current object to XML representation.
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string. 
  */
 public function toXml($xmlSerializer)
 {
     $array = array('MessageText' => $this->_messageText);
     $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName);
     return $xmlSerializer->serialize($array, $properties);
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer::objectSerialize
  */
 public function testObjectSerializeInvalidObject()
 {
     // Setup
     $this->setExpectedException(get_class(new \InvalidArgumentException()));
     // Test
     $actual = XmlSerializer::objectSerialize(null, null);
     // Assert
 }
Esempio n. 6
0
 /**
  * Converts this current object to XML representation.
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string.
  */
 public function toXml($xmlSerializer)
 {
     $properties = array(XmlSerializer::DEFAULT_TAG => 'SignedIdentifier', XmlSerializer::ROOT_NAME => self::$xmlRootName);
     return $xmlSerializer->serialize($this->toArray(), $properties);
 }
 /**
  * Converts this current object to XML representation.
  * 
  * @param XmlSerializer $xmlSerializer The XML serializer.
  * 
  * @return string
  */
 public function toXml($xmlSerializer)
 {
     $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName);
     return $xmlSerializer->serialize($this->toArray(), $properties);
 }