Skip to content

Commit

Permalink
throw exception if response is not a valid soap body
Browse files Browse the repository at this point in the history
  • Loading branch information
v1p3r75 committed Nov 6, 2024
1 parent da7eec0 commit d44086f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/SoapRequest/SoapResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $response
Expand All @@ -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<string, string> response
Expand Down
18 changes: 17 additions & 1 deletion tests/Feature/SoapRequest/SoapRequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,27 @@
</soap:Body>
</soap:Envelope>';

$data3 = '<html>
<head>
<title>Error</title>
</head>
<body>HTTP method POST is not supported by this URL</body>
</html>';

$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() {

Expand Down

0 comments on commit d44086f

Please sign in to comment.