Skip to content

Commit 4764543

Browse files
committed
Deprecate Group::listing()
1 parent 8f7e447 commit 4764543

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/kbsali/php-redmine-api/compare/v2.6.0...v2.x)
99

10+
### Added
11+
12+
- New method `Redmine\Api\Group::listNames()` for listing the ids and names of all groups.
13+
14+
### Deprecated
15+
16+
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
17+
1018
## [v2.6.0](https://github.com/kbsali/php-redmine-api/compare/v2.5.0...v2.6.0) - 2024-03-25
1119

1220
### Added

src/Redmine/Api/Group.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,17 @@ public function all(array $params = [])
101101
/**
102102
* Returns an array of groups with name/id pairs.
103103
*
104+
* @deprecated v2.7.0 Use listNames() instead.
105+
* @see Group::listNames()
106+
*
104107
* @param bool $forceUpdate to force the update of the groups var
105108
*
106109
* @return array list of groups (id => name)
107110
*/
108111
public function listing($forceUpdate = false)
109112
{
113+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
114+
110115
if (empty($this->groups) || $forceUpdate) {
111116
$this->groups = $this->list();
112117
}

tests/Unit/Api/GroupTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,38 @@ public function testAllReturnsClientGetResponseWithParameters()
113113
$this->assertSame($expectedReturn, $api->all($parameters));
114114
}
115115

116+
/**
117+
* Test listing().
118+
*/
119+
public function testListingTriggersDeprecationWarning()
120+
{
121+
$client = $this->createMock(Client::class);
122+
$client->method('requestGet')
123+
->willReturn(true);
124+
$client->method('getLastResponseBody')
125+
->willReturn('{"groups":[{"id":1,"name":"Group 1"},{"id":5,"name":"Group 5"}]}');
126+
$client->method('getLastResponseContentType')
127+
->willReturn('application/json');
128+
129+
$api = new Group($client);
130+
131+
// PHPUnit 10 compatible way to test trigger_error().
132+
set_error_handler(
133+
function ($errno, $errstr): bool {
134+
$this->assertSame(
135+
'`Redmine\Api\Group::listing()` is deprecated since v2.7.0, use `Redmine\Api\Group::listNames()` instead.',
136+
$errstr
137+
);
138+
139+
restore_error_handler();
140+
return true;
141+
},
142+
E_USER_DEPRECATED
143+
);
144+
145+
$api->listing();
146+
}
147+
116148
/**
117149
* Test listing().
118150
*/

0 commit comments

Comments
 (0)