Skip to content

Commit 32fd099

Browse files
committed
Deprecate Version::listing()
1 parent a95278b commit 32fd099

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

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

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

src/Redmine/Api/Version.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public function all($project, array $params = [])
125125
/**
126126
* Returns an array of name/id pairs (or id/name if not $reverse) of versions for $project.
127127
*
128+
* @deprecated v2.7.0 Use listNamesByProject() instead.
129+
* @see Version::listNamesByProject()
130+
*
128131
* @param string|int $project project id or literal identifier
129132
* @param bool $forceUpdate to force the update of the projects var
130133
* @param bool $reverse to return an array indexed by name rather than id
@@ -134,6 +137,8 @@ public function all($project, array $params = [])
134137
*/
135138
public function listing($project, $forceUpdate = false, $reverse = true, array $params = [])
136139
{
140+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED);
141+
137142
if (true === $forceUpdate || empty($this->versions)) {
138143
$this->versions = $this->listByProject($project, $params);
139144
}

tests/Unit/Api/VersionTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,38 @@ public function testListingCallsGetEveryTimeWithForceUpdate()
246246
$this->assertSame($expectedReturn, $api->listing(5, true));
247247
}
248248

249+
/**
250+
* Test listing().
251+
*/
252+
public function testListingTriggersDeprecationWarning()
253+
{
254+
$client = $this->createMock(Client::class);
255+
$client->method('requestGet')
256+
->willReturn(true);
257+
$client->method('getLastResponseBody')
258+
->willReturn('{"versions":[{"id":1,"name":"Version 1"},{"id":5,"name":"Version 5"}]}');
259+
$client->method('getLastResponseContentType')
260+
->willReturn('application/json');
261+
262+
$api = new Version($client);
263+
264+
// PHPUnit 10 compatible way to test trigger_error().
265+
set_error_handler(
266+
function ($errno, $errstr): bool {
267+
$this->assertSame(
268+
'`Redmine\Api\Version::listing()` is deprecated since v2.7.0, use `Redmine\Api\Version::listNamesByProject()` instead.',
269+
$errstr,
270+
);
271+
272+
restore_error_handler();
273+
return true;
274+
},
275+
E_USER_DEPRECATED,
276+
);
277+
278+
$api->listing(5);
279+
}
280+
249281
/**
250282
* Test getIdByName().
251283
*/
@@ -282,7 +314,6 @@ public function testGetIdByNameMakesGetRequest()
282314
*
283315
* @dataProvider invalidSharingProvider
284316
*
285-
*
286317
* @param string $sharingValue
287318
*/
288319
#[DataProvider('invalidSharingProvider')]

0 commit comments

Comments
 (0)