Skip to content

Commit b11e318

Browse files
committed
Deprecate Version::getIdByName()
1 parent 64e8df4 commit b11e318

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
- `Redmine\Api\User::listing()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
4040
- `Redmine\Api\User::getIdByUsername()` is deprecated, use `\Redmine\Api\User::listLogins()` instead.
4141
- `Redmine\Api\Version::listing()` is deprecated, use `\Redmine\Api\Version::listNamesByProject()` instead.
42+
- `Redmine\Api\Version::getIdByName()` is deprecated, use `\Redmine\Api\Version::listNamesByProject()` instead.
4243

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

src/Redmine/Api/Version.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ public function listing($project, $forceUpdate = false, $reverse = true, array $
145145
/**
146146
* Get an version id given its name and related project.
147147
*
148+
* @deprecated v2.7.0 Use listNamesByProject() instead.
149+
* @see Version::listNamesByProject()
150+
*
148151
* @param string|int $project project id or literal identifier
149152
* @param string $name The version name
150153
* @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 $
153156
*/
154157
public function getIdByName($project, $name, array $params = [])
155158
{
159+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);
160+
156161
$arr = $this->doListing($project, false, true, $params);
157162

158163
if (!isset($arr[$name])) {

tests/Unit/Api/VersionTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,35 @@ public function testGetIdByNameMakesGetRequest()
309309
$this->assertSame(5, $api->getIdByName(5, 'Version 5'));
310310
}
311311

312+
public function testGetIdByNameTriggersDeprecationWarning()
313+
{
314+
$client = $this->createMock(Client::class);
315+
$client->method('requestGet')
316+
->willReturn(true);
317+
$client->method('getLastResponseBody')
318+
->willReturn('{"versions":[{"id":1,"name":"Version 1"},{"id":5,"name":"Version 5"}]}');
319+
$client->method('getLastResponseContentType')
320+
->willReturn('application/json');
321+
322+
$api = new Version($client);
323+
324+
// PHPUnit 10 compatible way to test trigger_error().
325+
set_error_handler(
326+
function ($errno, $errstr): bool {
327+
$this->assertSame(
328+
'`Redmine\Api\Version::getIdByName()` is deprecated since v2.7.0, use `Redmine\Api\Version::listNamesByProject()` instead.',
329+
$errstr,
330+
);
331+
332+
restore_error_handler();
333+
return true;
334+
},
335+
E_USER_DEPRECATED,
336+
);
337+
338+
$api->getIdByName(5, 'Version 5');
339+
}
340+
312341
/**
313342
* Test validateSharing().
314343
*

0 commit comments

Comments
 (0)