Skip to content

Return false from AbstractApi::get() on empty response body #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function lastCallFailed()
* @param string $path
* @param bool $decodeIfJson
*
* @return string|array|SimpleXMLElement|null
* @return string|array|SimpleXMLElement|false
*/
protected function get($path, $decodeIfJson = true)
{
Expand All @@ -64,7 +64,7 @@ protected function get($path, $decodeIfJson = true)
}
}

return ('' === $body) ? null : $body;
return ('' === $body) ? false : $body;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/IssueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function all($issueId, array $params = [])
public function show($id)
{
$ret = $this->get('/relations/'.urlencode($id).'.json');
if (null === $ret) {
if (false === $ret) {
return [];
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public function getJsonDecodingFromGetMethodData()
['{"foo_bar": 12345}', null, ['foo_bar' => 12345]], // test decode by default
['{"foo_bar": 12345}', false, '{"foo_bar": 12345}'],
['{"foo_bar": 12345}', true, ['foo_bar' => 12345]],
['', true, null], // test decode with empty body
'Empty body, JSON decode: false' => ['', false, false],
'Empty body, JSON decode: true' => ['', true, false],
['{"foo_bar":', true, 'Error decoding body as JSON: Syntax error'], // test invalid JSON
];
}
Expand Down