/**
  * Extract media service entity from Atom Entry object
  *
  * @param WindowsAzure\Common\Internal\Atom\Entry $entry Atom Entry containing
  * properties of media services object
  *
  * @return array of properties name => value
  */
 protected function getPropertiesFromAtomEntry($entry)
 {
     Validate::notNull($entry, 'entry');
     Validate::isA($entry, 'WindowsAzure\\Common\\Internal\\Atom\\Entry', 'entry');
     $result = array();
     $content = $entry->getContent();
     if (!empty($content)) {
         $result = ContentPropertiesSerializer::unserialize($content->getXml()->children(Resources::DSM_XML_NAMESPACE));
     }
     return $result;
 }
 /**
  * @covers WindowsAzure\MediaServices\Internal\ContentPropertiesSerializer::serialize
  * @covers WindowsAzure\MediaServices\Internal\ContentPropertiesSerializer::_serializeRecursive
  */
 public function testSerializeCollection()
 {
     // Setup
     $taskBodyKey = 'TaskBody';
     $taskBody = 'TaskBody';
     $optionsKey = 'Options';
     $options = TaskOptions::NONE;
     $mediaProcessorIdKey = 'MediaProcessorId';
     $mediaProcessorId = 'MediaProcessorId';
     $errorKey = 'ErrorDetails';
     $errorCodeKey = 'Code';
     $errorCode = 1;
     $errorMessageKey = 'Message';
     $errorMessage = 'Error message';
     $error = array(array($errorCodeKey => $errorCode, $errorMessageKey => $errorMessage), array($errorCodeKey => $errorCode, $errorMessageKey => $errorMessage));
     $objArray = array($taskBodyKey => $taskBody, $optionsKey => $options, $mediaProcessorIdKey => $mediaProcessorId, $errorKey => $error);
     $obj = Task::createFromOptions($objArray);
     $expected = '
         <meta:properties xmlns:meta="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
             <data:' . $taskBodyKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $taskBody . '</data:' . $taskBodyKey . '>
             <data:' . $mediaProcessorIdKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $mediaProcessorId . '</data:' . $mediaProcessorIdKey . '>
             <data:' . $errorKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">
                 <data:element xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">
                     <data:' . $errorMessageKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $errorMessage . '</data:' . $errorMessageKey . '>
                     <data:' . $errorCodeKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $errorCode . '</data:' . $errorCodeKey . '>
                 </data:element>
                 <data:element xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">
                     <data:' . $errorMessageKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $errorMessage . '</data:' . $errorMessageKey . '>
                     <data:' . $errorCodeKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $errorCode . '</data:' . $errorCodeKey . '>
                 </data:element>
             </data:' . $errorKey . '>
         </meta:properties>
     ';
     // Test
     $result = ContentPropertiesSerializer::serialize($obj);
     // Assert
     $this->assertXmlStringEqualsXmlString($expected, $result);
 }
 /**
  * Get object properties as array
  *
  * @param object     $object    Source object
  * @param \XMLWriter $xmlWriter Xml writer to use
  *
  * @return  array
  */
 private static function _serializeRecursive($object, $xmlWriter)
 {
     Validate::notNull($object, 'object');
     $reflectionClass = new \ReflectionClass($object);
     $methodArray = $reflectionClass->getMethods();
     $result = array();
     foreach ($methodArray as $method) {
         if (strpos($method->name, 'get') === 0 && $method->isPublic()) {
             $variableName = substr($method->name, 3);
             $variableValue = $method->invoke($object);
             if (!empty($variableValue) || ContentPropertiesSerializer::_isRequired($object, $variableName)) {
                 if (is_a($variableValue, '\\DateTime')) {
                     $variableValue = $variableValue->format(\DateTime::ATOM);
                 }
                 if (gettype($variableValue) == 'array') {
                     $xmlWriter->startElementNS('data', $variableName, Resources::DS_XML_NAMESPACE);
                     foreach ($variableValue as $item) {
                         $xmlWriter->startElementNS('data', Resources::ELEMENT, Resources::DS_XML_NAMESPACE);
                         ContentPropertiesSerializer::_serializeRecursive($item, $xmlWriter);
                         $xmlWriter->endElement();
                     }
                     $xmlWriter->endElement();
                 } else {
                     if (gettype($variableValue) == 'object') {
                         $xmlWriter->startElementNS('data', $variableName, Resources::DS_XML_NAMESPACE);
                         ContentPropertiesSerializer::_serializeRecursive($variableValue, $xmlWriter);
                         $xmlWriter->endElement();
                     } else {
                         $xmlWriter->writeElementNS('data', $variableName, Resources::DS_XML_NAMESPACE, (string) $variableValue);
                     }
                 }
             }
         }
     }
     return $result;
 }