Skip to content

Commit

Permalink
restore BC in TimeEntry::all()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Dec 21, 2023
1 parent 8615d5a commit dd14a55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Redmine/Api/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/TimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Redmine\Api;

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

Expand Down Expand Up @@ -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();
}
}

/**
Expand Down
15 changes: 6 additions & 9 deletions tests/Unit/Api/TimeEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit dd14a55

Please sign in to comment.