/** * Create a response to emulate the response * * @param string $action name of the action to create response * @param array|string $data response content * * @return string */ public static function createResponse($action, $data) { //drop Request suffix $action = preg_replace('/Request$/', null, $action); $data['@attributes'] = ['xmlns' => 'urn:Qpay.POS.Gateway.ServiceContracts/']; $envelope = ['@attributes' => ['xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope/'], 's:Body' => ["{$action}Response" => $data]]; return Array2XML::createXML('s:Envelope', $envelope)->saveXML(); }
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); }