Skip to content

Commit

Permalink
refactor: Parse Output as Json or Return a String
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Sep 1, 2024
1 parent b93e607 commit 66b48b2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions webfiori/http/APITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace webfiori\http;

use PHPUnit\Framework\TestCase;
use webfiori\json\Json;
use webfiori\json\JsonException;
/**
* A helper class which is used to implement test cases for API calls.
*
Expand Down Expand Up @@ -101,8 +103,15 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,

$retVal = $manager->readOutputStream();
unlink(self::OUTPUT_STREAM);

return $retVal;

try {
$json = Json::decode($retVal);
$json->setIsFormatted(true);
return $json.'';
} catch (JsonException $ex) {
return $retVal;
}

}
private function parseVal($val) {
$type = gettype($val);
Expand Down

0 comments on commit 66b48b2

Please sign in to comment.