Skip to content

Commit

Permalink
Deprecate User::listing()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jul 8, 2024
1 parent 88effb9 commit 154903f
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 @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
- `Redmine\Api\User::listing()` is deprecated, use `\Redmine\Api\User::listLogins()` 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/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,18 @@ public function all(array $params = [])
/**
* Returns an array of users with login/id pairs.
*
* @deprecated v2.7.0 Use listLogins() instead.
* @see User::listLogins()
*
* @param bool $forceUpdate to force the update of the users var
* @param array $params to allow offset/limit (and more) to be passed
*
* @return array list of users (id => username)
*/
public function listing($forceUpdate = false, array $params = [])
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listLogins()` instead.', E_USER_DEPRECATED);

if (empty($this->users) || $forceUpdate) {
$this->users = $this->list($params);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Unit/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,36 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
$this->assertSame($expectedReturn, $api->listing(true));
$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('{"users":[{"id":1,"login":"user_1"},{"id":5,"login":"user_5"}]}');
$client->method('getLastResponseContentType')
->willReturn('application/json');

$api = new User($client);

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

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

$api->listing();
}
}

0 comments on commit 154903f

Please sign in to comment.