Skip to content

Commit

Permalink
Restore BC in TimeEntryActivity::all()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Dec 22, 2023
1 parent 8a4f7c3 commit beeaaf7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
14 changes: 12 additions & 2 deletions src/Redmine/Api/TimeEntryActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Redmine\Api;

use Redmine\Exception;

/**
* Listing time entry activities.
*
Expand Down Expand Up @@ -34,13 +36,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 entry activities found
* @return array|string|false list of time entry activities 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
28 changes: 16 additions & 12 deletions tests/Unit/Api/TimeEntryActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,38 @@ 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(
$this->stringStartsWith('/enumerations/time_entry_activities.json')
)
->with('/enumerations/time_entry_activities.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 TimeEntryActivity($client);

// Perform the tests
$this->assertSame($expectedReturn, $api->all());
$this->assertSame($expectedResponse, $api->all());
}

public static function getAllData(): array
{
return [
'array response' => ['["API Response"]', 'application/json', ['API Response']],
'string response' => ['"string"', 'application/json', 'Could not convert response body into array: "string"'],
'false response' => ['', 'application/json', false],
];
}

/**
Expand Down

0 comments on commit beeaaf7

Please sign in to comment.