Skip to content

Commit

Permalink
Deprecate CustomField::listing()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jun 28, 2024
1 parent 1a95695 commit 4e7e133
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 @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deprecated

- `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.

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

if (empty($this->customFields) || $forceUpdate) {
$this->customFields = $this->list($params);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Unit/Api/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,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('{"custom_fields":[{"id":1,"name":"CustomField 1"},{"id":5,"name":"CustomField 5"}]}');
$client->method('getLastResponseContentType')
->willReturn('application/json');

$api = new CustomField($client);

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

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

$api->listing();
}

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

0 comments on commit 4e7e133

Please sign in to comment.