Skip to content

Commit 97fa124

Browse files
committed
Deprecate Project::getIdByName()
1 parent 4dddac4 commit 97fa124

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
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNames()` instead.
3131
- `Redmine\Api\IssueStatus::getIdByName()` is deprecated, use `\Redmine\Api\IssueStatus::listNames()` instead.
3232
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
33+
- `Redmine\Api\Project::getIdByName()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
3334
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
3435
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
3536
- `Redmine\Api\Tracker::listing()` is deprecated, use `\Redmine\Api\Tracker::listNames()` instead.

src/Redmine/Api/Project.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ public function listing($forceUpdate = false, $reverse = true, array $params = [
138138
/**
139139
* Get a project id given its name.
140140
*
141+
* @deprecated v2.7.0 Use listNames() instead.
142+
* @see Project::listNames()
143+
*
141144
* @param string $name
142145
* @param array $params to allow offset/limit (and more) to be passed
143146
*
144147
* @return int|bool
145148
*/
146149
public function getIdByName($name, array $params = [])
147150
{
151+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
152+
148153
$arr = $this->doListing(false, true, $params);
149154

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

tests/Unit/Api/ProjectTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,35 @@ public function testGetIdByNameMakesGetRequest()
280280
$this->assertSame(5, $api->getIdByName('Project 5'));
281281
}
282282

283+
public function testGetIdByNameTriggersDeprecationWarning()
284+
{
285+
$client = $this->createMock(Client::class);
286+
$client->method('requestGet')
287+
->willReturn(true);
288+
$client->method('getLastResponseBody')
289+
->willReturn('{"projects":[{"id":1,"name":"Project 1"},{"id":5,"name":"Project 5"}]}');
290+
$client->method('getLastResponseContentType')
291+
->willReturn('application/json');
292+
293+
$api = new Project($client);
294+
295+
// PHPUnit 10 compatible way to test trigger_error().
296+
set_error_handler(
297+
function ($errno, $errstr): bool {
298+
$this->assertSame(
299+
'`Redmine\Api\Project::getIdByName()` is deprecated since v2.7.0, use `Redmine\Api\Project::listNames()` instead.',
300+
$errstr,
301+
);
302+
303+
restore_error_handler();
304+
return true;
305+
},
306+
E_USER_DEPRECATED,
307+
);
308+
309+
$api->getIdByName('Project 1');
310+
}
311+
283312
public function testDeprecatedPrepareParamsXml()
284313
{
285314
$client = $this->createMock(Client::class);

0 commit comments

Comments
 (0)