Skip to content

Commit

Permalink
Deprecate Version::getIdByName()
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jul 9, 2024
1 parent 64e8df4 commit b11e318
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Redmine\Api\User::listing()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
- `Redmine\Api\User::getIdByUsername()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
- `Redmine\Api\Version::listing()` is deprecated, use `\Redmine\Api\Version::listNamesByProject()` instead.
- `Redmine\Api\Version::getIdByName()` is deprecated, use `\Redmine\Api\Version::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/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
/**
* Get an version id given its name and related project.
*
* @deprecated v2.7.0 Use listNamesByProject() instead.
* @see Version::listNamesByProject()
*
* @param string|int $project project id or literal identifier
* @param string $name The version name
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
Expand All @@ -153,6 +156,8 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
*/
public function getIdByName($project, $name, array $params = [])
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);

$arr = $this->doListing($project, false, true, $params);

if (!isset($arr[$name])) {
Expand Down
29 changes: 29 additions & 0 deletions tests/Unit/Api/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,35 @@ public function testGetIdByNameMakesGetRequest()
$this->assertSame(5, $api->getIdByName(5, 'Version 5'));
}

public function testGetIdByNameTriggersDeprecationWarning()
{
$client = $this->createMock(Client::class);
$client->method('requestGet')
->willReturn(true);
$client->method('getLastResponseBody')
->willReturn('{"versions":[{"id":1,"name":"Version 1"},{"id":5,"name":"Version 5"}]}');
$client->method('getLastResponseContentType')
->willReturn('application/json');

$api = new Version($client);

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

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

$api->getIdByName(5, 'Version 5');
}

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

0 comments on commit b11e318

Please sign in to comment.