Skip to content

Commit

Permalink
fix(test): Added a Check for Value on Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane authored Aug 26, 2024
1 parent 32f9073 commit f4ab5a3
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions webfiori/http/APITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,

if ($method == 'GET' || $method == 'DELETE') {
foreach ($parameters as $key => $val) {
$_GET[$key] = $val;
$_GET[$key] = $this->parseVal($val);
}
$_GET['service'] = $apiEndpointName;
$this->unset($_GET, $parameters, $manager);
} else if ($method == 'POST' || $method == 'PUT') {
foreach ($parameters as $key => $val) {
$_POST[$key] = $val;
$_POST[$key] = $this->parseVal($val);
}
$_POST['service'] = $apiEndpointName;
$_SERVER['CONTENT_TYPE'] = 'multipart/form-data';
Expand All @@ -93,6 +93,26 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,

return $retVal;
}
private function parseVal($val) {
$type = gettype($val);

if ($type == 'array') {
$array = [];

foreach ($val as $arrVal) {
if (gettype($val) == 'string') {
$array[] = "'".$arrVal."'";
} else {
$array[] = $arrVal;
}
}

return implode(',', $array);
} else if ($type == 'boolean') {
return $type === true ? 'y' : 'n';
}
return $val;
}
/**
* Sends a DELETE request to specific endpoint.
*
Expand All @@ -109,14 +129,6 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
public function deletRequest(WebServicesManager $manager, string $endpoint, array $parameters = []) : string {
return $this->callEndpoint($manager, RequestMethod::DELETE, $endpoint, $parameters);
}
/**
* Returns HTTP response code that will be sent by the call.
*
* @return int An integer that represent HTTP response code.
*/
public function getResponseCode() : int {
return Response::getCode();
}
/**
* Sends a GET request to specific endpoint.
*
Expand Down

0 comments on commit f4ab5a3

Please sign in to comment.