diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3323d6..e28570b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Redmine/Api/Version.php b/src/Redmine/Api/Version.php index 3b7a8502..7d11cca2 100644 --- a/src/Redmine/Api/Version.php +++ b/src/Redmine/Api/Version.php @@ -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, ...) @@ -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])) { diff --git a/tests/Unit/Api/VersionTest.php b/tests/Unit/Api/VersionTest.php index 0ed55c06..7666934e 100644 --- a/tests/Unit/Api/VersionTest.php +++ b/tests/Unit/Api/VersionTest.php @@ -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(). *