Skip to content

Commit 56bdb6b

Browse files
committed
Deprecate IssueStatus::getIdByName()
1 parent 057de97 commit 56bdb6b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Redmine/Api/IssueStatus.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,17 @@ public function listing($forceUpdate = false)
116116
/**
117117
* Get a status id given its name.
118118
*
119+
* @deprecated v2.7.0 Use listNames() instead.
120+
* @see IssueStatus::listNames()
121+
*
119122
* @param string $name
120123
*
121124
* @return int|false
122125
*/
123126
public function getIdByName($name)
124127
{
128+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
129+
125130
$arr = $this->doListing(false);
126131

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

tests/Unit/Api/IssueStatusTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,33 @@ public function testGetIdByNameMakesGetRequest()
277277
$this->assertFalse($api->getIdByName('IssueStatus 1'));
278278
$this->assertSame(5, $api->getIdByName('IssueStatus 5'));
279279
}
280+
281+
public function testGetIdByNameTriggersDeprecationWarning()
282+
{
283+
$client = $this->createMock(Client::class);
284+
$client->method('requestGet')
285+
->willReturn(true);
286+
$client->method('getLastResponseBody')
287+
->willReturn('{"issue_statuses":[{"id":1,"name":"IssueStatus 1"},{"id":5,"name":"IssueStatus 5"}]}');
288+
$client->method('getLastResponseContentType')
289+
->willReturn('application/json');
290+
291+
$api = new IssueStatus($client);
292+
293+
// PHPUnit 10 compatible way to test trigger_error().
294+
set_error_handler(
295+
function ($errno, $errstr): bool {
296+
$this->assertSame(
297+
'`Redmine\Api\IssueStatus::getIdByName()` is deprecated since v2.7.0, use `Redmine\Api\IssueStatus::listNames()` instead.',
298+
$errstr,
299+
);
300+
301+
restore_error_handler();
302+
return true;
303+
},
304+
E_USER_DEPRECATED,
305+
);
306+
307+
$api->getIdByName('IssueStatus 5');
308+
}
280309
}

0 commit comments

Comments
 (0)