diff --git a/src/Redmine/Api/Search.php b/src/Redmine/Api/Search.php index 54ca7fb9..015fa766 100644 --- a/src/Redmine/Api/Search.php +++ b/src/Redmine/Api/Search.php @@ -39,7 +39,7 @@ final public function listByQuery(string $query, array $params = []): array * @param string $query string to search * @param array $params optional parameters to be passed to the api (offset, limit, ...) * - * @return array list of results (projects, issues) + * @return array|string|false list of results (projects, issues) found or error message or false */ public function search($query, array $params = []) { diff --git a/src/Redmine/Api/TimeEntry.php b/src/Redmine/Api/TimeEntry.php index 2bf71752..9f233422 100644 --- a/src/Redmine/Api/TimeEntry.php +++ b/src/Redmine/Api/TimeEntry.php @@ -2,6 +2,7 @@ namespace Redmine\Api; +use Redmine\Exception; use Redmine\Exception\MissingParameterException; use Redmine\Serializer\XmlSerializer; @@ -41,13 +42,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 time entries found + * @return array|string|false list of time entries 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(); + } } /** diff --git a/tests/Unit/Api/TimeEntryTest.php b/tests/Unit/Api/TimeEntryTest.php index 5f407da4..582aaf9b 100644 --- a/tests/Unit/Api/TimeEntryTest.php +++ b/tests/Unit/Api/TimeEntryTest.php @@ -45,32 +45,29 @@ function ($errno, $errstr): bool { * Test all(). * * @covers ::all + * @dataProvider getAllData * @test */ - public function testAllReturnsClientGetResponse() + public function testAllReturnsClientGetResponse($response, $responseType, $expectedResponse) { - // Test values - $response = '["API Response"]'; - $expectedReturn = ['API Response']; - // Create the used mock objects $client = $this->createMock(Client::class); - $client->expects($this->once()) + $client->expects($this->exactly(1)) ->method('requestGet') ->with('/time_entries.json') ->willReturn(true); - $client->expects($this->exactly(1)) + $client->expects($this->atLeast(1)) ->method('getLastResponseBody') ->willReturn($response); $client->expects($this->exactly(1)) ->method('getLastResponseContentType') - ->willReturn('application/json'); + ->willReturn($responseType); // Create the object under test $api = new TimeEntry($client); // Perform the tests - $this->assertSame($expectedReturn, $api->all()); + $this->assertSame($expectedResponse, $api->all()); } /**