Skip to content

Commit

Permalink
Deprecate IssueStatus::listing()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jul 1, 2024
1 parent e30fcf9 commit a426080
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Redmine\Api\CustomField::listing()` is deprecated, use `\Redmine\Api\CustomField::listNames()` instead.
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNamesByProject()` instead.

## [v2.6.0](https://github.com/kbsali/php-redmine-api/compare/v2.5.0...v2.6.0) - 2024-03-25

Expand Down
5 changes: 5 additions & 0 deletions src/Redmine/Api/IssueStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ public function all(array $params = [])
/**
* Returns an array of issue statuses with name/id pairs.
*
* @deprecated v2.7.0 Use listNames() instead.
* @see IssueStatus::listNames()
*
* @param bool $forceUpdate to force the update of the statuses var
*
* @return array list of issue statuses (id => name)
*/
public function listing($forceUpdate = false)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

if (empty($this->issueStatuses) || $forceUpdate) {
$this->issueStatuses = $this->list();
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Unit/Api/IssueStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,38 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
$this->assertSame($expectedReturn, $api->listing(true));
}

/**
* Test listing().
*/
public function testListingTriggersDeprecationWarning()
{
$client = $this->createMock(Client::class);
$client->method('requestGet')
->willReturn(true);
$client->method('getLastResponseBody')
->willReturn('{"issue_statuses":[{"id":1,"name":"IssueStatus 1"},{"id":5,"name":"IssueStatus 5"}]}');
$client->method('getLastResponseContentType')
->willReturn('application/json');

$api = new IssueStatus($client);

// PHPUnit 10 compatible way to test trigger_error().
set_error_handler(
function ($errno, $errstr): bool {
$this->assertSame(
'`Redmine\Api\IssueStatus::listing()` is deprecated since v2.7.0, use `Redmine\Api\IssueStatus::listNames()` instead.',
$errstr,
);

restore_error_handler();
return true;
},
E_USER_DEPRECATED,
);

$api->listing();
}

/**
* Test getIdByName().
*/
Expand Down

0 comments on commit a426080

Please sign in to comment.