Skip to content

Commit 2b56273

Browse files
authored
Merge pull request #73 from WebFiori/dev
Dev
2 parents 14cec41 + 594c617 commit 2b56273

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

.gitattributes

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
#perform LF normalization
2+
* text eol=crlf
3+
*.php text eol=crlf
4+
*.html text eol=crlf
15
# Files and folders here will be not included when creating package
26
/tests export-ignore
37
/examples export-ignore
48
/.github export-ignore
59
/.gitignore export-ignore
610
/.travis.yml export-ignore
7-
/phpunit.xml export-ignore
8-
/sonar-project.properties export-ignore
11+
/phpunit.xml export-ignore
12+
/ecs.php export-ignore
13+
/php_cs.php.dist export-ignore
14+
/phpbench.json export-ignore
15+
/sonar-project.properties export-ignore
16+
/ecs.php export-ignore
17+
/CHANGELOG.md export-ignore
18+
/release-commit.php export-ignore
19+
/release-please-manifest.json export-ignore
20+
/release-please-config.json export-ignore

webfiori/http/APITestCase.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function addFile(string $fileIdx, string $filePath, bool $reset = false)
101101
* @return string The method will return the output of the endpoint.
102102
*/
103103
public function callEndpoint(WebServicesManager $manager, string $requestMethod, string $apiEndpointName, array $parameters = [], array $httpHeaders = []) : string {
104-
$manager->setOutputStream(fopen(self::DEFAULT_OUTPUT_STREAM,'w'));
104+
$manager->setOutputStream(fopen($this->getOutputFile(),'w'));
105105
$method = strtoupper($requestMethod);
106106
putenv('REQUEST_METHOD='.$method);
107107

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

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

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

141141
}
142+
/**
143+
* Creates a formatted string from calling an API.
144+
*
145+
* This helper method can be used to format JSON output of calling an API
146+
* and use it in assertions. The goal of the method is to initially format
147+
* the out put, display it as string and the developer copies the output
148+
* and modify it as needed.
149+
*
150+
* @param string $output
151+
*/
152+
public function format(string $output) {
153+
$expl = explode(self::NL, $output);
154+
$nl = '.self::NL\n';
155+
$count = count($expl);
156+
157+
for ($x = 0 ; $x < count($expl) ; $x++) {
158+
if ($x + 1 == $count) {
159+
$nl = '';
160+
}
161+
echo ". '$expl[$x]]'".$nl;
162+
}
163+
}
142164
private function parseVal($val) {
143165
$type = gettype($val);
144166

0 commit comments

Comments
 (0)