Skip to content
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

Restore BC in all() methods with empty Redmine response #337

Merged
merged 28 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
21a0891
Add test for empty Redmine response
Art4 Dec 18, 2023
8839842
Merge branch 'v2.x' into 335-catch-error-on-empty-response-body
Art4 Dec 19, 2023
e237917
Replace deprecated PHPUnit method getMockForAbstractClass()
Art4 Dec 19, 2023
9fa08c3
Add dataProvider for testDeprecatedRetrieveAll
Art4 Dec 19, 2023
308be81
restore BC in AbstractApi::retrieveAll()
Art4 Dec 20, 2023
e8649fd
Add test for json response not containing object or array
Art4 Dec 21, 2023
83b5762
BC: let retrieveAll return false on empty response body
Art4 Dec 21, 2023
44be88b
restore BC in CustomField::all()
Art4 Dec 21, 2023
53e4f70
restore BC in Group::all()
Art4 Dec 21, 2023
6a7a139
restore BC in Issue::all()
Art4 Dec 21, 2023
c60b11f
Restore BC in IssueCategory::all()
Art4 Dec 21, 2023
1e166d2
restore BC in IssuePriority::all()
Art4 Dec 21, 2023
96d5bf1
Restore BC in IssueRelation::all()
Art4 Dec 21, 2023
8c44e5e
Restore BC in IssueStatus::all()
Art4 Dec 21, 2023
287cc08
Restore BC in Membership::all()
Art4 Dec 21, 2023
9c7dd63
Restore BC in News::all()
Art4 Dec 21, 2023
8707b84
Restore BC in Project::all()
Art4 Dec 21, 2023
93f7d4d
Restore BC in Query::all()
Art4 Dec 21, 2023
6aed628
Restore BC in Role::all()
Art4 Dec 21, 2023
8615d5a
restore BC in Search::search()
Art4 Dec 21, 2023
dd14a55
restore BC in TimeEntry::all()
Art4 Dec 21, 2023
8a4f7c3
Add missing dataProvider
Art4 Dec 21, 2023
beeaaf7
Restore BC in TimeEntryActivity::all()
Art4 Dec 22, 2023
e458e97
Restore BC in Tracker::all()
Art4 Dec 22, 2023
e3c509b
Restore BC in User::all()
Art4 Dec 22, 2023
8b8c54b
Restore BC in Version::all()
Art4 Dec 22, 2023
98f39bf
Restore BC in Wiki::all()
Art4 Dec 22, 2023
5dbecd0
Add throws phpdoc tag to list() methods
Art4 Dec 22, 2023
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
12 changes: 9 additions & 3 deletions src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Redmine\Api;
use Redmine\Client\Client;
use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Serializer\JsonSerializer;
use Redmine\Serializer\PathSerializer;
Expand Down Expand Up @@ -169,16 +170,20 @@ protected function sanitizeParams(array $defaults, array $params)
* @param string $endpoint API end point
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array|false elements found
* @return array|string|false elements found or error message or false
*/
protected function retrieveAll($endpoint, array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.2.0, use `retrieveData()` instead.', E_USER_DEPRECATED);

try {
$data = $this->retrieveData(strval($endpoint), $params);
} catch (SerializerException $e) {
$data = false;
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}

return $data;
Expand Down Expand Up @@ -307,6 +312,7 @@ protected function attachCustomFieldXML(SimpleXMLElement $xml, array $fields)
private function getLastResponseBodyAsArray(): array
{
$body = $this->client->getLastResponseBody();

$contentType = $this->client->getLastResponseContentType();
$returnData = null;

Expand Down
17 changes: 15 additions & 2 deletions src/Redmine/Api/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\SerializerException;

/**
* Listing custom fields.
*
Expand All @@ -20,6 +23,8 @@ class CustomField extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array list of custom fields found
*/
final public function list(array $params = []): array
Expand All @@ -38,13 +43,21 @@ final public function list(array $params = []): array
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of custom fields found
* @return array|string|false list of custom fields found or error message or false
*/
public function all(array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);

return $this->list($params);
try {
return $this->list($params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down
19 changes: 15 additions & 4 deletions src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Redmine\Api;

use Exception;
use Redmine\Exception;
use Redmine\Exception\MissingParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;

Expand All @@ -25,6 +26,8 @@ class Group extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array list of groups found
*/
final public function list(array $params = []): array
Expand All @@ -43,13 +46,21 @@ final public function list(array $params = []): array
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of groups found
* @return array|string|false list of groups found or error message or false
*/
public function all(array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);

return $this->list($params);
try {
return $this->list($params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down Expand Up @@ -114,7 +125,7 @@ public function create(array $params = [])
*/
public function update($id, array $params = [])
{
throw new Exception('Not implemented');
throw new \Exception('Not implemented');
}

/**
Expand Down
16 changes: 14 additions & 2 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Serializer\JsonSerializer;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;
Expand Down Expand Up @@ -38,6 +40,8 @@ class Issue extends AbstractApi
*
* @param array $params the additional parameters (cf available $params above)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array list of issues found
*/
final public function list(array $params = []): array
Expand All @@ -64,13 +68,21 @@ final public function list(array $params = []): array
*
* @param array $params the additional parameters (cf available $params above)
*
* @return array list of issues found
* @return array|string|false list of issues found or error message or false
*/
public function all(array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);

return $this->list($params);
try {
return $this->list($params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down
15 changes: 13 additions & 2 deletions src/Redmine/Api/IssueCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\InvalidParameterException;
use Redmine\Exception\MissingParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;

Expand All @@ -27,6 +29,7 @@ class IssueCategory extends AbstractApi
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws InvalidParameterException if $projectIdentifier is not of type int or string
* @throws SerializerException if response body could not be converted into array
*
* @return array list of issue categories found
*/
Expand Down Expand Up @@ -54,13 +57,21 @@ final public function listByProject($projectIdentifier, array $params = []): arr
* @param string|int $project project id or literal identifier
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of issue categories found
* @return array|string|false list of issue categories found or error message or false
*/
public function all($project, array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::listByProject()` instead.', E_USER_DEPRECATED);

return $this->listByProject(strval($project), $params);
try {
return $this->listByProject(strval($project), $params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/Redmine/Api/IssuePriority.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\SerializerException;

/**
* Listing issue priorities.
*
Expand All @@ -20,6 +23,8 @@ class IssuePriority extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array list of issue priorities found
*/
final public function list(array $params = []): array
Expand All @@ -38,12 +43,20 @@ final public function list(array $params = []): array
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of issue priorities found
* @return array|string|false list of issue priorities found or error message or false
*/
public function all(array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);

return $this->list($params);
try {
return $this->list($params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}
}
16 changes: 14 additions & 2 deletions src/Redmine/Api/IssueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Serializer\JsonSerializer;

/**
Expand All @@ -23,6 +25,8 @@ class IssueRelation extends AbstractApi
* @param int $issueId the issue id
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array list of relations found
*/
final public function listByIssueId(int $issueId, array $params = []): array
Expand All @@ -42,13 +46,21 @@ final public function listByIssueId(int $issueId, array $params = []): array
* @param int $issueId the issue id
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of relations found
* @return array|string|false list of relations found or error message or false
*/
public function all($issueId, array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::listByIssueId()` instead.', E_USER_DEPRECATED);

return $this->listByIssueId($issueId, $params);
try {
return $this->listByIssueId($issueId, $params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/Redmine/Api/IssueStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\SerializerException;

/**
* Listing issue statuses.
*
Expand All @@ -20,6 +23,8 @@ class IssueStatus extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
*
* @return array list of issue statuses found
*/
final public function list(array $params = []): array
Expand All @@ -38,13 +43,21 @@ final public function list(array $params = []): array
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of issue statuses found
* @return array|string|false list of issue statuses found or error message or false
*/
public function all(array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);

return $this->list($params);
try {
return $this->list($params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down
15 changes: 13 additions & 2 deletions src/Redmine/Api/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Redmine\Api;

use Redmine\Exception;
use Redmine\Exception\InvalidParameterException;
use Redmine\Exception\MissingParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Serializer\XmlSerializer;

/**
Expand All @@ -26,6 +28,7 @@ class Membership extends AbstractApi
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws InvalidParameterException if $projectIdentifier is not of type int or string
* @throws SerializerException if response body could not be converted into array
*
* @return array list of memberships found
*/
Expand Down Expand Up @@ -53,13 +56,21 @@ final public function listByProject($projectIdentifier, array $params = []): arr
* @param string|int $project project id or literal identifier
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of memberships found
* @return array|string|false list of memberships found or error message or false
*/
public function all($project, array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::listByProject()` instead.', E_USER_DEPRECATED);

return $this->listByProject(strval($project), $params);
try {
return $this->listByProject(strval($project), $params);
} catch (Exception $e) {
if ($this->client->getLastResponseBody() === '') {
return false;
}

return $e->getMessage();
}
}

/**
Expand Down
Loading