Skip to content

Commit 44719cd

Browse files
committed
Deprecate Project::listing()
1 parent 4e0dec6 commit 44719cd

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
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
2222
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
2323
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNamesByProject()` instead.
24+
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNamesByProject()` instead.
2425

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

src/Redmine/Api/Project.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public function all(array $params = [])
119119
/**
120120
* Returns an array of projects with name/id pairs (or id/name if $reserse is false).
121121
*
122+
* @deprecated v2.7.0 Use listNames() instead.
123+
* @see Project::listNames()
124+
*
122125
* @param bool $forceUpdate to force the update of the projects var
123126
* @param bool $reverse to return an array indexed by name rather than id
124127
* @param array $params to allow offset/limit (and more) to be passed
@@ -127,6 +130,8 @@ public function all(array $params = [])
127130
*/
128131
public function listing($forceUpdate = false, $reverse = true, array $params = [])
129132
{
133+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
134+
130135
if (true === $forceUpdate || empty($this->projects)) {
131136
$this->projects = $this->list($params);
132137
}

tests/Unit/Api/ProjectTest.php

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

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

0 commit comments

Comments
 (0)