public function testCreateArray()
 {
     $xml = '<ROOT><node><child>string</child></node></ROOT>';
     $originArray = ['ROOT' => ['node' => ['child' => 'string']]];
     $array = XML2Array::createArray($xml);
     self::assertEquals($originArray, $array);
 }
 public function testToArrayToXML()
 {
     $sampleFile = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'sample.xml');
     $xmlArray = XML2Array::createArray($sampleFile);
     $xml = Array2XML::createXML('ROOT', $xmlArray);
     $xml = $xml->saveXML($xml->firstChild->firstChild);
     //remove spaces for comparison
     $sampleFile = preg_replace('/(>)\\s+/', null, $sampleFile);
     $xml = preg_replace('/(>)\\s+/', null, $xml);
     self::assertEquals($sampleFile, $xml);
 }
 /**
  * Parse QPay response and return array of the body content
  *
  * @param string          $string
  * @param QPayApiResponse $responseObject if present the object properties will be populated with the response content
  *
  * @return array|mixed content of the return statement
  * @throws \Exception
  */
 public static function parseResponse($string, QPayApiResponse $responseObject = null)
 {
     $string = self::cleanXml($string);
     /** @var array $array */
     $array = XML2Array::createArray($string);
     if (isset($array['Envelope']['Body']) && ($responseBody = $array['Envelope']['Body']) && is_array(current($responseBody)) && strpos(current(array_keys($responseBody)), 'Response') !== false) {
         $array = current($responseBody);
         if (is_object($responseObject)) {
             self::populateResponseObject($array, $responseObject);
         }
     }
     return $array;
 }