Skip to content

Commit

Permalink
Merge pull request #73 from WebFiori/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
usernane authored Dec 24, 2024
2 parents 14cec41 + 594c617 commit 2b56273
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
16 changes: 14 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#perform LF normalization
* text eol=crlf
*.php text eol=crlf
*.html text eol=crlf
# Files and folders here will be not included when creating package
/tests export-ignore
/examples export-ignore
/.github export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/sonar-project.properties export-ignore
/phpunit.xml export-ignore
/ecs.php export-ignore
/php_cs.php.dist export-ignore
/phpbench.json export-ignore
/sonar-project.properties export-ignore
/ecs.php export-ignore
/CHANGELOG.md export-ignore
/release-commit.php export-ignore
/release-please-manifest.json export-ignore
/release-please-config.json export-ignore
26 changes: 24 additions & 2 deletions webfiori/http/APITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function addFile(string $fileIdx, string $filePath, bool $reset = false)
* @return string The method will return the output of the endpoint.
*/
public function callEndpoint(WebServicesManager $manager, string $requestMethod, string $apiEndpointName, array $parameters = [], array $httpHeaders = []) : string {
$manager->setOutputStream(fopen(self::DEFAULT_OUTPUT_STREAM,'w'));
$manager->setOutputStream(fopen($this->getOutputFile(),'w'));
$method = strtoupper($requestMethod);
putenv('REQUEST_METHOD='.$method);

Expand All @@ -128,7 +128,7 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
}

$retVal = $manager->readOutputStream();
unlink(self::DEFAULT_OUTPUT_STREAM);
unlink($this->getOutputFile());

try {
$json = Json::decode($retVal);
Expand All @@ -139,6 +139,28 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
}

}
/**
* Creates a formatted string from calling an API.
*
* This helper method can be used to format JSON output of calling an API
* and use it in assertions. The goal of the method is to initially format
* the out put, display it as string and the developer copies the output
* and modify it as needed.
*
* @param string $output
*/
public function format(string $output) {
$expl = explode(self::NL, $output);
$nl = '.self::NL\n';
$count = count($expl);

for ($x = 0 ; $x < count($expl) ; $x++) {
if ($x + 1 == $count) {
$nl = '';
}
echo ". '$expl[$x]]'".$nl;
}
}
private function parseVal($val) {
$type = gettype($val);

Expand Down

0 comments on commit 2b56273

Please sign in to comment.