Skip to content

Commit 8194bd1

Browse files
committed
Deprecate IssueCategory::listing()
1 parent a025097 commit 8194bd1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Redmine/Api/IssueCategory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,18 @@ public function all($project, array $params = [])
125125
/**
126126
* Returns an array of categories with name/id pairs.
127127
*
128+
* @deprecated v2.7.0 Use listNamesByProject() instead.
129+
* @see Group::listNames()
130+
*
128131
* @param string|int $project project id or literal identifier
129132
* @param bool $forceUpdate to force the update of the projects var
130133
*
131134
* @return array list of projects (id => project name)
132135
*/
133136
public function listing($project, $forceUpdate = false)
134137
{
138+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);
139+
135140
if (true === $forceUpdate || empty($this->issueCategories)) {
136141
$this->issueCategories = $this->listByProject($project);
137142
}

tests/Unit/Api/IssueCategoryTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,38 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
219219
$this->assertSame($expectedReturn, $api->listing(5, true));
220220
}
221221

222+
/**
223+
* Test listing().
224+
*/
225+
public function testListingTriggersDeprecationWarning()
226+
{
227+
$client = $this->createMock(Client::class);
228+
$client->method('requestGet')
229+
->willReturn(true);
230+
$client->method('getLastResponseBody')
231+
->willReturn('{"issue_categories":[{"id":1,"name":"IssueCategory 1"},{"id":5,"name":"IssueCategory 5"}]}');
232+
$client->method('getLastResponseContentType')
233+
->willReturn('application/json');
234+
235+
$api = new IssueCategory($client);
236+
237+
// PHPUnit 10 compatible way to test trigger_error().
238+
set_error_handler(
239+
function ($errno, $errstr): bool {
240+
$this->assertSame(
241+
'`Redmine\Api\IssueCategory::listing()` is deprecated since v2.7.0, use `Redmine\Api\IssueCategory::listNamesByProject()` instead.',
242+
$errstr,
243+
);
244+
245+
restore_error_handler();
246+
return true;
247+
},
248+
E_USER_DEPRECATED,
249+
);
250+
251+
$api->listing(5);
252+
}
253+
222254
/**
223255
* Test getIdByName().
224256
*/

0 commit comments

Comments
 (0)