diff --git a/src/SoapRequest/SoapResponseParser.php b/src/SoapRequest/SoapResponseParser.php index 649ea7a..34e24d3 100644 --- a/src/SoapRequest/SoapResponseParser.php +++ b/src/SoapRequest/SoapResponseParser.php @@ -13,10 +13,12 @@ public static function parse(string $body): MoovMoneyApiResponse try { $xml = new \SimpleXMLElement($body); - var_dump($body); - die(); - - $response = $xml->children("soap", true)->Body->children("ns2", true)->children(); + + $response = $xml->children("soap", true)?->Body?->children("ns2", true)?->children(); + + if (is_null($response)) { + throw new Exception(); + } /** * @var array $response @@ -37,10 +39,12 @@ public static function parseError(string $body): string try { $xml = new \SimpleXMLElement($body); - var_dump($body); - die(); - $response = $xml->children("soap", true)->Body->children("soap", true)->children(); + $response = $xml->children("soap", true)?->Body?->children("soap", true)?->children(); + + if (is_null($response)) { + throw new Exception(); + } /** * @var array response diff --git a/tests/Feature/SoapRequest/SoapRequestParserTest.php b/tests/Feature/SoapRequest/SoapRequestParserTest.php index b9bb439..a130e40 100644 --- a/tests/Feature/SoapRequest/SoapRequestParserTest.php +++ b/tests/Feature/SoapRequest/SoapRequestParserTest.php @@ -67,11 +67,27 @@ '; + $data3 = ' + + Error + + + HTTP method POST is not supported by this URL + '; + + $response = SoapResponseParser::parseError($data); + + expect($response)->toBeString->toBe('[soap:Server] : "For input string"'); + $response = SoapResponseParser::parseError($data2); expect($response)->toBeString->toBe('[Error] : "An error has occurred"'); -}); + $response = SoapResponseParser::parseError($data3); + + expect($response)->toBeString->toBe('[Error] : "An error has occurred"'); + +})->throws(ServerErrorException::class); // it('should throw an exception if the body is not a valid xml string [success]', function() {