Skip to content

Commit a87333b

Browse files
committed
Deprecate Tracker::listing()
1 parent 81b7023 commit a87333b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
2828
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
2929
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
30+
- `Redmine\Api\Tracker::listing()` is deprecated, use `\Redmine\Api\Tracker::listNames()` instead.
3031

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

src/Redmine/Api/Tracker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ public function all(array $params = [])
9898
/**
9999
* Returns an array of trackers with name/id pairs.
100100
*
101+
* @deprecated v2.7.0 Use listNames() instead.
102+
* @see Tracker::listNames()
103+
*
101104
* @param bool $forceUpdate to force the update of the trackers var
102105
*
103106
* @return array list of trackers (id => name)
104107
*/
105108
public function listing($forceUpdate = false)
106109
{
110+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
111+
107112
if (empty($this->trackers) || $forceUpdate) {
108113
$this->trackers = $this->list();
109114
}

tests/Unit/Api/TrackerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,38 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
215215
$this->assertSame($expectedReturn, $api->listing(true));
216216
}
217217

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

0 commit comments

Comments
 (0)