Skip to content

Commit 4e7e133

Browse files
committed
Deprecate CustomField::listing()
1 parent 1a95695 commit 4e7e133

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
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Deprecated
1717

18+
- `Redmine\Api\CustomField::listing()` is deprecated, use `\Redmine\Api\CustomField::listNames()` instead.
1819
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
1920
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
2021

src/Redmine/Api/CustomField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,18 @@ public function all(array $params = [])
9999
/**
100100
* Returns an array of custom fields with name/id pairs.
101101
*
102+
* @deprecated v2.7.0 Use listNames() instead.
103+
* @see CustomField::listNames()
104+
*
102105
* @param bool $forceUpdate to force the update of the custom fields var
103106
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
104107
*
105108
* @return array list of custom fields (id => name)
106109
*/
107110
public function listing($forceUpdate = false, array $params = [])
108111
{
112+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
113+
109114
if (empty($this->customFields) || $forceUpdate) {
110115
$this->customFields = $this->list($params);
111116
}

tests/Unit/Api/CustomFieldTest.php

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

290+
/**
291+
* Test listing().
292+
*/
293+
public function testListingTriggersDeprecationWarning()
294+
{
295+
$client = $this->createMock(Client::class);
296+
$client->method('requestGet')
297+
->willReturn(true);
298+
$client->method('getLastResponseBody')
299+
->willReturn('{"custom_fields":[{"id":1,"name":"CustomField 1"},{"id":5,"name":"CustomField 5"}]}');
300+
$client->method('getLastResponseContentType')
301+
->willReturn('application/json');
302+
303+
$api = new CustomField($client);
304+
305+
// PHPUnit 10 compatible way to test trigger_error().
306+
set_error_handler(
307+
function ($errno, $errstr): bool {
308+
$this->assertSame(
309+
'`Redmine\Api\CustomField::listing()` is deprecated since v2.7.0, use `Redmine\Api\CustomField::listNames()` instead.',
310+
$errstr,
311+
);
312+
313+
restore_error_handler();
314+
return true;
315+
},
316+
E_USER_DEPRECATED,
317+
);
318+
319+
$api->listing();
320+
}
321+
290322
/**
291323
* Test getIdByName().
292324
*/

0 commit comments

Comments
 (0)