Skip to content

Commit 154903f

Browse files
committed
Deprecate User::listing()
1 parent 88effb9 commit 154903f

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
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
2828
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
2929
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
30+
- `Redmine\Api\User::listing()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
3031

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

src/Redmine/Api/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,18 @@ public function all(array $params = [])
118118
/**
119119
* Returns an array of users with login/id pairs.
120120
*
121+
* @deprecated v2.7.0 Use listLogins() instead.
122+
* @see User::listLogins()
123+
*
121124
* @param bool $forceUpdate to force the update of the users var
122125
* @param array $params to allow offset/limit (and more) to be passed
123126
*
124127
* @return array list of users (id => username)
125128
*/
126129
public function listing($forceUpdate = false, array $params = [])
127130
{
131+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listLogins()` instead.', E_USER_DEPRECATED);
132+
128133
if (empty($this->users) || $forceUpdate) {
129134
$this->users = $this->list($params);
130135
}

tests/Unit/Api/UserTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,36 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
286286
$this->assertSame($expectedReturn, $api->listing(true));
287287
$this->assertSame($expectedReturn, $api->listing(true));
288288
}
289+
290+
/**
291+
* Test listing().
292+
*/
293+
public function testListingTriggersDeprecationWarning()
294+
{
295+
$client = $this->createMock(Client::class);
296+
$client->method('requestGet')
297+
->willReturn(true);
298+
$client->method('getLastResponseBody')
299+
->willReturn('{"users":[{"id":1,"login":"user_1"},{"id":5,"login":"user_5"}]}');
300+
$client->method('getLastResponseContentType')
301+
->willReturn('application/json');
302+
303+
$api = new User($client);
304+
305+
// PHPUnit 10 compatible way to test trigger_error().
306+
set_error_handler(
307+
function ($errno, $errstr): bool {
308+
$this->assertSame(
309+
'`Redmine\Api\User::listing()` is deprecated since v2.7.0, use `Redmine\Api\User::listLogins()` instead.',
310+
$errstr,
311+
);
312+
313+
restore_error_handler();
314+
return true;
315+
},
316+
E_USER_DEPRECATED,
317+
);
318+
319+
$api->listing();
320+
}
289321
}

0 commit comments

Comments
 (0)