From 93cef18bd87e4770bef516044d849ba05c4f7ca7 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 30 Jan 2024 14:51:55 +0100 Subject: [PATCH 1/3] Add method UnexpectedResponseException::getResponse() --- .../Exception/UnexpectedResponseException.php | 30 ++++++++++++- .../UnexpectedResponseExceptionTest.php | 45 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Exception/UnexpectedResponseExceptionTest.php diff --git a/src/Redmine/Exception/UnexpectedResponseException.php b/src/Redmine/Exception/UnexpectedResponseException.php index 1a68d419..0555f2b1 100644 --- a/src/Redmine/Exception/UnexpectedResponseException.php +++ b/src/Redmine/Exception/UnexpectedResponseException.php @@ -1,9 +1,13 @@ getCode() : 1, + $prev + ); + + $e->response = $response; + + return $e; + } + + public function getResponse(): ?Response + { + return $this->response; + } +} diff --git a/tests/Unit/Exception/UnexpectedResponseExceptionTest.php b/tests/Unit/Exception/UnexpectedResponseExceptionTest.php new file mode 100644 index 00000000..58d0a606 --- /dev/null +++ b/tests/Unit/Exception/UnexpectedResponseExceptionTest.php @@ -0,0 +1,45 @@ +createMock(Response::class); + + $exception = UnexpectedResponseException::create($response); + + $this->assertInstanceOf(Exception::class, $exception); + $this->assertInstanceOf(RedmineException::class, $exception); + } + + public function testCreateWithThrowable() + { + $response = $this->createMock(Response::class); + $throwable = new Exception('message', 5); + + $exception = UnexpectedResponseException::create($response, $throwable); + + $this->assertSame(5, $exception->getCode()); + $this->assertSame($throwable, $exception->getPrevious()); + } + + public function testGetResponseReturnsResponse() + { + $response = $this->createMock(Response::class); + + $exception = UnexpectedResponseException::create($response); + + $this->assertSame($response, $exception->getResponse()); + $this->assertInstanceOf(RedmineException::class, $exception); + } +} From 57a6ed3fcb2ed5406024dc945cc70ac4852b491f Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 30 Jan 2024 15:05:57 +0100 Subject: [PATCH 2/3] Make use of factory method, change error message --- src/Redmine/Api/CustomField.php | 2 +- src/Redmine/Api/Group.php | 2 +- src/Redmine/Api/Issue.php | 2 +- src/Redmine/Api/IssueCategory.php | 2 +- src/Redmine/Api/IssuePriority.php | 2 +- src/Redmine/Api/IssueRelation.php | 2 +- src/Redmine/Api/IssueStatus.php | 2 +- src/Redmine/Api/Membership.php | 2 +- src/Redmine/Api/News.php | 4 ++-- src/Redmine/Api/Project.php | 10 +++++----- src/Redmine/Api/Query.php | 2 +- src/Redmine/Api/Role.php | 2 +- src/Redmine/Api/Search.php | 2 +- src/Redmine/Api/TimeEntry.php | 2 +- src/Redmine/Api/TimeEntryActivity.php | 2 +- src/Redmine/Api/Tracker.php | 2 +- src/Redmine/Api/User.php | 2 +- src/Redmine/Api/Version.php | 2 +- src/Redmine/Api/Wiki.php | 2 +- src/Redmine/Exception/UnexpectedResponseException.php | 8 ++------ tests/Unit/Api/CustomField/ListTest.php | 2 +- tests/Unit/Api/Group/ListTest.php | 2 +- tests/Unit/Api/Issue/ListTest.php | 2 +- tests/Unit/Api/IssueCategory/ListByProjectTest.php | 2 +- tests/Unit/Api/IssuePriority/ListTest.php | 2 +- tests/Unit/Api/IssueRelation/ListByIssueIdTest.php | 2 +- tests/Unit/Api/IssueStatus/ListTest.php | 2 +- tests/Unit/Api/Membership/ListByProjectTest.php | 2 +- tests/Unit/Api/News/ListByProjectTest.php | 2 +- tests/Unit/Api/News/ListTest.php | 2 +- tests/Unit/Api/Project/ArchiveTest.php | 2 +- tests/Unit/Api/Project/CloseTest.php | 2 +- tests/Unit/Api/Project/ListTest.php | 2 +- tests/Unit/Api/Project/ReopenTest.php | 2 +- tests/Unit/Api/Project/UnarchiveTest.php | 2 +- tests/Unit/Api/Query/ListTest.php | 2 +- tests/Unit/Api/Role/ListTest.php | 2 +- tests/Unit/Api/Search/ListByQueryTest.php | 2 +- tests/Unit/Api/TimeEntry/ListTest.php | 2 +- tests/Unit/Api/TimeEntryActivity/ListTest.php | 2 +- tests/Unit/Api/Tracker/ListTest.php | 2 +- tests/Unit/Api/User/ListTest.php | 2 +- tests/Unit/Api/Version/ListByProjectTest.php | 2 +- tests/Unit/Api/Wiki/ListByProjectTest.php | 2 +- 44 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/Redmine/Api/CustomField.php b/src/Redmine/Api/CustomField.php index fe33074a..ae81b6d1 100644 --- a/src/Redmine/Api/CustomField.php +++ b/src/Redmine/Api/CustomField.php @@ -33,7 +33,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/custom_fields.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Group.php b/src/Redmine/Api/Group.php index 622695d0..48130afc 100644 --- a/src/Redmine/Api/Group.php +++ b/src/Redmine/Api/Group.php @@ -37,7 +37,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/groups.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Issue.php b/src/Redmine/Api/Issue.php index 12f7cab5..58f9e4c0 100644 --- a/src/Redmine/Api/Issue.php +++ b/src/Redmine/Api/Issue.php @@ -78,7 +78,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/issues.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/IssueCategory.php b/src/Redmine/Api/IssueCategory.php index 6686c908..8bddd95f 100644 --- a/src/Redmine/Api/IssueCategory.php +++ b/src/Redmine/Api/IssueCategory.php @@ -46,7 +46,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr try { return $this->retrieveData('/projects/' . strval($projectIdentifier) . '/issue_categories.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/IssuePriority.php b/src/Redmine/Api/IssuePriority.php index 0fbf0523..2a639096 100644 --- a/src/Redmine/Api/IssuePriority.php +++ b/src/Redmine/Api/IssuePriority.php @@ -33,7 +33,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/enumerations/issue_priorities.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/IssueRelation.php b/src/Redmine/Api/IssueRelation.php index 0084265c..3e93015e 100644 --- a/src/Redmine/Api/IssueRelation.php +++ b/src/Redmine/Api/IssueRelation.php @@ -35,7 +35,7 @@ final public function listByIssueId(int $issueId, array $params = []): array try { return $this->retrieveData('/issues/' . strval($issueId) . '/relations.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/IssueStatus.php b/src/Redmine/Api/IssueStatus.php index 81dcc4fc..07e39924 100644 --- a/src/Redmine/Api/IssueStatus.php +++ b/src/Redmine/Api/IssueStatus.php @@ -33,7 +33,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/issue_statuses.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Membership.php b/src/Redmine/Api/Membership.php index 130decf8..265af375 100644 --- a/src/Redmine/Api/Membership.php +++ b/src/Redmine/Api/Membership.php @@ -45,7 +45,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr try { return $this->retrieveData('/projects/' . strval($projectIdentifier) . '/memberships.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/News.php b/src/Redmine/Api/News.php index 5cecbca0..e81f1ccb 100644 --- a/src/Redmine/Api/News.php +++ b/src/Redmine/Api/News.php @@ -41,7 +41,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr try { return $this->retrieveData('/projects/' . strval($projectIdentifier) . '/news.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } @@ -61,7 +61,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/news.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Project.php b/src/Redmine/Api/Project.php index 29bbc9f4..0caa3123 100755 --- a/src/Redmine/Api/Project.php +++ b/src/Redmine/Api/Project.php @@ -37,7 +37,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/projects.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } @@ -224,7 +224,7 @@ final public function close($projectIdentifier): bool $lastResponse = $this->getLastResponse(); if ($lastResponse->getStatusCode() !== 204) { - throw new UnexpectedResponseException('The Redmine server replied with the status code ' . $lastResponse->getStatusCode()); + throw UnexpectedResponseException::create($lastResponse); } return true; @@ -259,7 +259,7 @@ final public function reopen($projectIdentifier): bool $lastResponse = $this->getLastResponse(); if ($lastResponse->getStatusCode() !== 204) { - throw new UnexpectedResponseException('The Redmine server replied with the status code ' . $lastResponse->getStatusCode()); + throw UnexpectedResponseException::create($lastResponse); } return true; @@ -294,7 +294,7 @@ final public function archive($projectIdentifier): bool $lastResponse = $this->getLastResponse(); if ($lastResponse->getStatusCode() !== 204) { - throw new UnexpectedResponseException('The Redmine server replied with the status code ' . $lastResponse->getStatusCode()); + throw UnexpectedResponseException::create($lastResponse); } return true; @@ -329,7 +329,7 @@ final public function unarchive($projectIdentifier): bool $lastResponse = $this->getLastResponse(); if ($lastResponse->getStatusCode() !== 204) { - throw new UnexpectedResponseException('The Redmine server replied with the status code ' . $lastResponse->getStatusCode()); + throw UnexpectedResponseException::create($lastResponse); } return true; diff --git a/src/Redmine/Api/Query.php b/src/Redmine/Api/Query.php index 7b15316b..85b52d3c 100644 --- a/src/Redmine/Api/Query.php +++ b/src/Redmine/Api/Query.php @@ -33,7 +33,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/queries.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Role.php b/src/Redmine/Api/Role.php index 574f856e..8a33ca65 100644 --- a/src/Redmine/Api/Role.php +++ b/src/Redmine/Api/Role.php @@ -33,7 +33,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/roles.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Search.php b/src/Redmine/Api/Search.php index c287d7c9..efbfeedc 100644 --- a/src/Redmine/Api/Search.php +++ b/src/Redmine/Api/Search.php @@ -32,7 +32,7 @@ final public function listByQuery(string $query, array $params = []): array try { return $this->retrieveData('/search.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/TimeEntry.php b/src/Redmine/Api/TimeEntry.php index 0d1cae16..1b32b1b2 100644 --- a/src/Redmine/Api/TimeEntry.php +++ b/src/Redmine/Api/TimeEntry.php @@ -35,7 +35,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/time_entries.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/TimeEntryActivity.php b/src/Redmine/Api/TimeEntryActivity.php index cc2b8264..ed496348 100644 --- a/src/Redmine/Api/TimeEntryActivity.php +++ b/src/Redmine/Api/TimeEntryActivity.php @@ -31,7 +31,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/enumerations/time_entry_activities.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Tracker.php b/src/Redmine/Api/Tracker.php index c69418a4..60df6a03 100644 --- a/src/Redmine/Api/Tracker.php +++ b/src/Redmine/Api/Tracker.php @@ -33,7 +33,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/trackers.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/User.php b/src/Redmine/Api/User.php index f82784c2..e7152290 100644 --- a/src/Redmine/Api/User.php +++ b/src/Redmine/Api/User.php @@ -36,7 +36,7 @@ final public function list(array $params = []): array try { return $this->retrieveData('/users.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Version.php b/src/Redmine/Api/Version.php index d5ec42f9..366fa350 100644 --- a/src/Redmine/Api/Version.php +++ b/src/Redmine/Api/Version.php @@ -44,7 +44,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr try { return $this->retrieveData('/projects/' . strval($projectIdentifier) . '/versions.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Api/Wiki.php b/src/Redmine/Api/Wiki.php index 24599129..1b2c3002 100644 --- a/src/Redmine/Api/Wiki.php +++ b/src/Redmine/Api/Wiki.php @@ -44,7 +44,7 @@ final public function listByProject($projectIdentifier, array $params = []): arr try { return $this->retrieveData('/projects/' . strval($projectIdentifier) . '/wiki/index.json', $params); } catch (SerializerException $th) { - throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th); + throw UnexpectedResponseException::create($this->getLastResponse(), $th); } } diff --git a/src/Redmine/Exception/UnexpectedResponseException.php b/src/Redmine/Exception/UnexpectedResponseException.php index 0555f2b1..c2de6af5 100644 --- a/src/Redmine/Exception/UnexpectedResponseException.php +++ b/src/Redmine/Exception/UnexpectedResponseException.php @@ -12,11 +12,7 @@ /** * Exception if the Redmine server delivers an unexpected response. * - * Use the following methods to investigate the response: - * - * - Redmine\Client\Client::getLastResponseStatusCode() - * - Redmine\Client\Client::getLastResponseContentType() - * - Redmine\Client\Client::getLastResponseBody() + * Use `getResponse()` to investigate the response */ final class UnexpectedResponseException extends RuntimeException implements RedmineException { @@ -28,7 +24,7 @@ final class UnexpectedResponseException extends RuntimeException implements Redm public static function create(Response $response, Throwable $prev = null): self { $e = new self( - 'The Redmine server responded with an unexpected body.', + 'The Redmine server replied with an unexpected response.', ($prev !== null) ? $prev->getCode() : 1, $prev ); diff --git a/tests/Unit/Api/CustomField/ListTest.php b/tests/Unit/Api/CustomField/ListTest.php index 67a0c136..3d79e09f 100644 --- a/tests/Unit/Api/CustomField/ListTest.php +++ b/tests/Unit/Api/CustomField/ListTest.php @@ -150,7 +150,7 @@ public function testListThrowsException() $api = new CustomField($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Group/ListTest.php b/tests/Unit/Api/Group/ListTest.php index 203c14dc..ff41c229 100644 --- a/tests/Unit/Api/Group/ListTest.php +++ b/tests/Unit/Api/Group/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new Group($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Issue/ListTest.php b/tests/Unit/Api/Issue/ListTest.php index 8245f04a..3a9ea99c 100644 --- a/tests/Unit/Api/Issue/ListTest.php +++ b/tests/Unit/Api/Issue/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new Issue($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/IssueCategory/ListByProjectTest.php b/tests/Unit/Api/IssueCategory/ListByProjectTest.php index 2f50610d..6a40ec13 100644 --- a/tests/Unit/Api/IssueCategory/ListByProjectTest.php +++ b/tests/Unit/Api/IssueCategory/ListByProjectTest.php @@ -114,7 +114,7 @@ public function testListByProjectThrowsException() $api = new IssueCategory($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByProject(5); diff --git a/tests/Unit/Api/IssuePriority/ListTest.php b/tests/Unit/Api/IssuePriority/ListTest.php index 3733d4eb..19a3a540 100644 --- a/tests/Unit/Api/IssuePriority/ListTest.php +++ b/tests/Unit/Api/IssuePriority/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new IssuePriority($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/IssueRelation/ListByIssueIdTest.php b/tests/Unit/Api/IssueRelation/ListByIssueIdTest.php index b03a5739..a69a613d 100644 --- a/tests/Unit/Api/IssueRelation/ListByIssueIdTest.php +++ b/tests/Unit/Api/IssueRelation/ListByIssueIdTest.php @@ -84,7 +84,7 @@ public function testListByIssueIdThrowsException() $api = new IssueRelation($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByIssueId(5); diff --git a/tests/Unit/Api/IssueStatus/ListTest.php b/tests/Unit/Api/IssueStatus/ListTest.php index ed23646a..9affbd5d 100644 --- a/tests/Unit/Api/IssueStatus/ListTest.php +++ b/tests/Unit/Api/IssueStatus/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new IssueStatus($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Membership/ListByProjectTest.php b/tests/Unit/Api/Membership/ListByProjectTest.php index 975d187e..100fd765 100644 --- a/tests/Unit/Api/Membership/ListByProjectTest.php +++ b/tests/Unit/Api/Membership/ListByProjectTest.php @@ -112,7 +112,7 @@ public function testListByProjectThrowsException() $api = new Membership($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByProject(5); diff --git a/tests/Unit/Api/News/ListByProjectTest.php b/tests/Unit/Api/News/ListByProjectTest.php index a2bd817f..863196bb 100644 --- a/tests/Unit/Api/News/ListByProjectTest.php +++ b/tests/Unit/Api/News/ListByProjectTest.php @@ -114,7 +114,7 @@ public function testListByProjectThrowsException() $api = new News($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByProject(5); diff --git a/tests/Unit/Api/News/ListTest.php b/tests/Unit/Api/News/ListTest.php index f4db14d8..ec31cf16 100644 --- a/tests/Unit/Api/News/ListTest.php +++ b/tests/Unit/Api/News/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new News($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Project/ArchiveTest.php b/tests/Unit/Api/Project/ArchiveTest.php index 25c1bb77..89f94298 100644 --- a/tests/Unit/Api/Project/ArchiveTest.php +++ b/tests/Unit/Api/Project/ArchiveTest.php @@ -50,7 +50,7 @@ public function testArchiveThrowsUnexpectedResponseException() $api = new Project($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server replied with the status code 403'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); $api->archive(5); } diff --git a/tests/Unit/Api/Project/CloseTest.php b/tests/Unit/Api/Project/CloseTest.php index 4067b769..94c1ef5c 100644 --- a/tests/Unit/Api/Project/CloseTest.php +++ b/tests/Unit/Api/Project/CloseTest.php @@ -49,7 +49,7 @@ public function testCloseThrowsUnexpectedResponseException() $api = new Project($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server replied with the status code 403'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); $api->close(5); } diff --git a/tests/Unit/Api/Project/ListTest.php b/tests/Unit/Api/Project/ListTest.php index 26efd4b3..e85de578 100644 --- a/tests/Unit/Api/Project/ListTest.php +++ b/tests/Unit/Api/Project/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new Project($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Project/ReopenTest.php b/tests/Unit/Api/Project/ReopenTest.php index 5e64785f..91c985af 100644 --- a/tests/Unit/Api/Project/ReopenTest.php +++ b/tests/Unit/Api/Project/ReopenTest.php @@ -48,7 +48,7 @@ public function testReopenThrowsUnexpectedResponseException() $api = new Project($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server replied with the status code 403'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); $api->reopen(5); } diff --git a/tests/Unit/Api/Project/UnarchiveTest.php b/tests/Unit/Api/Project/UnarchiveTest.php index 84a16568..9c347e9c 100644 --- a/tests/Unit/Api/Project/UnarchiveTest.php +++ b/tests/Unit/Api/Project/UnarchiveTest.php @@ -49,7 +49,7 @@ public function testUnarchiveThrowsUnexpectedResponseException() $api = new Project($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server replied with the status code 403'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); $api->unarchive(5); } diff --git a/tests/Unit/Api/Query/ListTest.php b/tests/Unit/Api/Query/ListTest.php index 5858fb3e..fd39cc35 100644 --- a/tests/Unit/Api/Query/ListTest.php +++ b/tests/Unit/Api/Query/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new Query($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Role/ListTest.php b/tests/Unit/Api/Role/ListTest.php index 276af29d..ec1dd55f 100644 --- a/tests/Unit/Api/Role/ListTest.php +++ b/tests/Unit/Api/Role/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new Role($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Search/ListByQueryTest.php b/tests/Unit/Api/Search/ListByQueryTest.php index 8cc25ff2..3d284e0a 100644 --- a/tests/Unit/Api/Search/ListByQueryTest.php +++ b/tests/Unit/Api/Search/ListByQueryTest.php @@ -85,7 +85,7 @@ public function testListByQueryThrowsException() $api = new Search($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByQuery('query'); diff --git a/tests/Unit/Api/TimeEntry/ListTest.php b/tests/Unit/Api/TimeEntry/ListTest.php index b5b24b06..963414b0 100644 --- a/tests/Unit/Api/TimeEntry/ListTest.php +++ b/tests/Unit/Api/TimeEntry/ListTest.php @@ -88,7 +88,7 @@ public function testListThrowsException() $api = new TimeEntry($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/TimeEntryActivity/ListTest.php b/tests/Unit/Api/TimeEntryActivity/ListTest.php index b5f1deb0..439817dc 100644 --- a/tests/Unit/Api/TimeEntryActivity/ListTest.php +++ b/tests/Unit/Api/TimeEntryActivity/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new TimeEntryActivity($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Tracker/ListTest.php b/tests/Unit/Api/Tracker/ListTest.php index b6a7b465..8318b44b 100644 --- a/tests/Unit/Api/Tracker/ListTest.php +++ b/tests/Unit/Api/Tracker/ListTest.php @@ -84,7 +84,7 @@ public function testListThrowsException() $api = new Tracker($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/User/ListTest.php b/tests/Unit/Api/User/ListTest.php index 7f1b016d..8d0f1311 100644 --- a/tests/Unit/Api/User/ListTest.php +++ b/tests/Unit/Api/User/ListTest.php @@ -87,7 +87,7 @@ public function testListThrowsException() $api = new User($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->list(); diff --git a/tests/Unit/Api/Version/ListByProjectTest.php b/tests/Unit/Api/Version/ListByProjectTest.php index 349347a4..a9fca8d5 100644 --- a/tests/Unit/Api/Version/ListByProjectTest.php +++ b/tests/Unit/Api/Version/ListByProjectTest.php @@ -115,7 +115,7 @@ public function testListByProjectThrowsException() $api = new Version($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByProject(5); diff --git a/tests/Unit/Api/Wiki/ListByProjectTest.php b/tests/Unit/Api/Wiki/ListByProjectTest.php index fc99da2d..1a336e5e 100644 --- a/tests/Unit/Api/Wiki/ListByProjectTest.php +++ b/tests/Unit/Api/Wiki/ListByProjectTest.php @@ -115,7 +115,7 @@ public function testListByProjectThrowsException() $api = new Wiki($client); $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('The Redmine server responded with an unexpected body.'); + $this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); // Perform the tests $api->listByProject(5); From 4433cf0c9f877d805c101a3df06c22ae1c1087f1 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 30 Jan 2024 15:30:29 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d707826..c2507b14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New method `Redmine\Api\Project::reopen()` to reopen a project. - New method `Redmine\Api\Project::archive()` to archive a project. - New method `Redmine\Api\Project::unarchive()` to unarchive a project. +- New method `UnexpectedResponseException::getResponse()` to get the last response responsible for the exception. ### Changed @@ -35,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New method `Redmine\Api\News::list()` to list news from all project. - New method `Redmine\Api\News::listByProject()` to list news from a project. - New method `Redmine\Api\Project::list()` to list projects. -- New method `Redmine\Api\Query::list()` to list projects. +- New method `Redmine\Api\Query::list()` to list queries. - New method `Redmine\Api\Role::list()` to list roles. - New method `Redmine\Api\Search::listByQuery()` to list search results by query. - New method `Redmine\Api\TimeEntry::list()` to list time entries.