Skip to content

Commit 05bc969

Browse files
committed
Deprecate Role::listing()
1 parent 957ab4b commit 05bc969

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
2222
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
2323
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNamesByProject()` instead.
24+
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNamesByProject()` instead.
2425

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

src/Redmine/Api/Role.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,17 @@ public function all(array $params = [])
100100
/**
101101
* Returns an array of roles with name/id pairs.
102102
*
103+
* @deprecated v2.7.0 Use listNames() instead.
104+
* @see Role::listNames()
105+
*
103106
* @param bool $forceUpdate to force the update of the roles var
104107
*
105108
* @return array list of roles (id => name)
106109
*/
107110
public function listing($forceUpdate = false)
108111
{
112+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
113+
109114
if (empty($this->roles) || $forceUpdate) {
110115
$this->roles = $this->list();
111116
}

tests/Unit/Api/RoleTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,36 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
214214
$this->assertSame($expectedReturn, $api->listing(true));
215215
$this->assertSame($expectedReturn, $api->listing(true));
216216
}
217+
218+
/**
219+
* Test listing().
220+
*/
221+
public function testListingTriggersDeprecationWarning()
222+
{
223+
$client = $this->createMock(Client::class);
224+
$client->method('requestGet')
225+
->willReturn(true);
226+
$client->method('getLastResponseBody')
227+
->willReturn('{"roles":[{"id":1,"name":"Role 1"},{"id":5,"name":"Role 5"}]}');
228+
$client->method('getLastResponseContentType')
229+
->willReturn('application/json');
230+
231+
$api = new Role($client);
232+
233+
// PHPUnit 10 compatible way to test trigger_error().
234+
set_error_handler(
235+
function ($errno, $errstr): bool {
236+
$this->assertSame(
237+
'`Redmine\Api\Role::listing()` is deprecated since v2.7.0, use `Redmine\Api\Role::listNames()` instead.',
238+
$errstr,
239+
);
240+
241+
restore_error_handler();
242+
return true;
243+
},
244+
E_USER_DEPRECATED,
245+
);
246+
247+
$api->listing();
248+
}
217249
}

0 commit comments

Comments
 (0)