Skip to content

Commit a2ea0d4

Browse files
committed
Merge branch 'v2.x' into add-role-listnames
2 parents 05bc969 + 8fab7fb commit a2ea0d4

File tree

8 files changed

+336
-23
lines changed

8 files changed

+336
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- New method `Redmine\Api\Group::listNames()` for listing the ids and names of all groups.
1414
- New method `Redmine\Api\IssueCategory::listNamesByProject()` for listing the ids and names of all issue categories of a project.
1515
- New method `Redmine\Api\IssueStatus::listNames()` for listing the ids and names of all issue statuses.
16+
- New method `Redmine\Api\Project::listNames()` for listing the ids and names of all projects.
1617
- New method `Redmine\Api\Role::listNames()` for listing the ids and names of all roles.
1718

1819
### Deprecated
@@ -21,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2122
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
2223
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
2324
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNamesByProject()` instead.
25+
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNamesByProject()` instead.
2426
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNamesByProject()` instead.
2527

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

src/Redmine/Api/Project.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Project extends AbstractApi
2424
{
2525
private $projects = [];
2626

27+
private $projectNames = null;
28+
2729
/**
2830
* List projects.
2931
*
@@ -44,6 +46,43 @@ final public function list(array $params = []): array
4446
}
4547
}
4648

49+
/**
50+
* Returns an array of all projects with id/name pairs.
51+
*
52+
* @return array<int,string> list of projects (id => name)
53+
*/
54+
final public function listNames(): array
55+
{
56+
if ($this->projectNames !== null) {
57+
return $this->projectNames;
58+
}
59+
60+
$this->projectNames = [];
61+
62+
$limit = 100;
63+
$offset = 0;
64+
65+
do {
66+
$list = $this->list([
67+
'limit' => $limit,
68+
'offset' => $offset,
69+
]);
70+
71+
$listCount = 0;
72+
$offset += $limit;
73+
74+
if (array_key_exists('projects', $list)) {
75+
$listCount = count($list['projects']);
76+
77+
foreach ($list['projects'] as $issueStatus) {
78+
$this->projectNames[(int) $issueStatus['id']] = (string) $issueStatus['name'];
79+
}
80+
}
81+
} while ($listCount === $limit);
82+
83+
return $this->projectNames;
84+
}
85+
4786
/**
4887
* List projects.
4988
*
@@ -80,6 +119,9 @@ public function all(array $params = [])
80119
/**
81120
* Returns an array of projects with name/id pairs (or id/name if $reserse is false).
82121
*
122+
* @deprecated v2.7.0 Use listNames() instead.
123+
* @see Project::listNames()
124+
*
83125
* @param bool $forceUpdate to force the update of the projects var
84126
* @param bool $reverse to return an array indexed by name rather than id
85127
* @param array $params to allow offset/limit (and more) to be passed
@@ -88,6 +130,8 @@ public function all(array $params = [])
88130
*/
89131
public function listing($forceUpdate = false, $reverse = true, array $params = [])
90132
{
133+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
134+
91135
if (true === $forceUpdate || empty($this->projects)) {
92136
$this->projects = $this->list($params);
93137
}

tests/Behat/Bootstrap/IssueCategoryContextTrait.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@
99

1010
trait IssueCategoryContextTrait
1111
{
12+
/**
13+
* @Given I create :count issue categories for project identifier :identifier
14+
*/
15+
public function iCreateIssueCategoriesForProjectIdentifier(int $count, $identifier)
16+
{
17+
while ($count > 0) {
18+
$this->iCreateAnIssueCategoryForProjectIdentifierAndWithTheName(
19+
$identifier,
20+
'Issue Category ' . $count,
21+
);
22+
23+
$count--;
24+
}
25+
}
26+
27+
/**
28+
* @When I create an issue category for project identifier :identifier and with the name :name
29+
*/
30+
public function iCreateAnIssueCategoryForProjectIdentifierAndWithTheName($identifier, $name)
31+
{
32+
$table = new TableNode([
33+
['property', 'value'],
34+
['name', $name],
35+
]);
36+
37+
$this->iCreateAnIssueCategoryForProjectIdentifierAndWithTheFollowingData($identifier, $table);
38+
}
39+
1240
/**
1341
* @When I create an issue category for project identifier :identifier and with the following data
1442
*/

tests/Behat/Bootstrap/ProjectContextTrait.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ public function iCreateAProjectWithTheFollowingData(TableNode $table)
4343
);
4444
}
4545

46+
/**
47+
* @Given I create :count projects
48+
*/
49+
public function iCreateProjects(int $count)
50+
{
51+
while ($count > 0) {
52+
$this->iCreateAProjectWithNameAndIdentifier('Test Project ' . $count, 'test-project-' . $count);
53+
54+
$count--;
55+
}
56+
}
57+
4658
/**
4759
* @When I list all projects
4860
*/
@@ -57,6 +69,20 @@ public function iListAllProjects()
5769
);
5870
}
5971

72+
/**
73+
* @When I list all project names
74+
*/
75+
public function iListAllProjectNames()
76+
{
77+
/** @var Project */
78+
$api = $this->getNativeCurlClient()->getApi('project');
79+
80+
$this->registerClientResponse(
81+
$api->listNames(),
82+
$api->getLastResponse(),
83+
);
84+
}
85+
6086
/**
6187
* @When I show the project with identifier :identifier
6288
*/

tests/Behat/features/issue_category.feature

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Feature: Interacting with the REST API for issue categories
77
Scenario: Creating an issue category with miminal data
88
Given I have a "NativeCurlClient" client
99
And I create a project with name "Test Project" and identifier "test-project"
10-
When I create an issue category for project identifier "test-project" and with the following data
11-
| property | value |
12-
| name | Category name |
10+
When I create an issue category for project identifier "test-project" and with the name "Category name"
1311
Then the response has the status code "201"
1412
And the response has the content type "application/xml"
1513
And the returned data is an instance of "SimpleXMLElement"
@@ -101,12 +99,8 @@ Feature: Interacting with the REST API for issue categories
10199
Scenario: Listing of multiple issue categories
102100
Given I have a "NativeCurlClient" client
103101
And I create a project with name "Test Project" and identifier "test-project"
104-
And I create an issue category for project identifier "test-project" and with the following data
105-
| property | value |
106-
| name | Category name B |
107-
And I create an issue category for project identifier "test-project" and with the following data
108-
| property | value |
109-
| name | Category name A |
102+
And I create an issue category for project identifier "test-project" and with the name "Category name B"
103+
And I create an issue category for project identifier "test-project" and with the name "Category name A"
110104
When I list all issue categories for project identifier "test-project"
111105
Then the response has the status code "200"
112106
And the response has the content type "application/json"
@@ -154,12 +148,8 @@ Feature: Interacting with the REST API for issue categories
154148
Scenario: Listing of multiple issue category names
155149
Given I have a "NativeCurlClient" client
156150
And I create a project with name "Test Project" and identifier "test-project"
157-
And I create an issue category for project identifier "test-project" and with the following data
158-
| property | value |
159-
| name | Category name B |
160-
And I create an issue category for project identifier "test-project" and with the following data
161-
| property | value |
162-
| name | Category name A |
151+
And I create an issue category for project identifier "test-project" and with the name "Category name B"
152+
And I create an issue category for project identifier "test-project" and with the name "Category name A"
163153
When I list all issue category names for project identifier "test-project"
164154
Then the response has the status code "200"
165155
And the response has the content type "application/json"
@@ -168,13 +158,19 @@ Feature: Interacting with the REST API for issue categories
168158
| 1 | Category name B |
169159
| 2 | Category name A |
170160

161+
Scenario: Listing a lot of issue category names
162+
Given I have a "NativeCurlClient" client
163+
And I create a project with name "Test Project" and identifier "test-project"
164+
And I create "108" issue categories for project identifier "test-project"
165+
When I list all issue category names for project identifier "test-project"
166+
Then the response has the status code "200"
167+
And the response has the content type "application/json"
168+
And the returned data contains "108" items
169+
171170
Scenario: Updating an issue category with all data
172171
Given I have a "NativeCurlClient" client
173172
And I create a project with name "Test Project" and identifier "test-project"
174-
And I create an issue category for project identifier "test-project" and with the following data
175-
| property | value |
176-
| name | Category name |
177-
| assigned_to_id | 1 |
173+
And I create an issue category for project identifier "test-project" and with the name "Category name"
178174
When I update the issue category with id "1" and the following data
179175
| property | value |
180176
| name | New category name |
@@ -187,10 +183,7 @@ Feature: Interacting with the REST API for issue categories
187183
Scenario: Deleting an issue category
188184
Given I have a "NativeCurlClient" client
189185
And I create a project with name "Test Project" and identifier "test-project"
190-
And I create an issue category for project identifier "test-project" and with the following data
191-
| property | value |
192-
| name | Category name |
193-
| assigned_to_id | 1 |
186+
And I create an issue category for project identifier "test-project" and with the name "Category name"
194187
When I remove the issue category with id "1"
195188
Then the response has the status code "204"
196189
And the response has an empty content type

tests/Behat/features/projects.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ Feature: Interacting with the REST API for projects
150150
updated_on
151151
"""
152152

153+
Scenario: Listing of multiple project names
154+
Given I have a "NativeCurlClient" client
155+
And I create a project with name "Test Project B" and identifier "test-project1"
156+
And I create a project with name "Test Project A" and identifier "test-project2"
157+
When I list all project names
158+
Then the response has the status code "200"
159+
And the response has the content type "application/json"
160+
And the returned data contains "2" items
161+
And the returned data has proterties with the following data
162+
| property | value |
163+
| 1 | Test Project B |
164+
| 2 | Test Project A |
165+
166+
Scenario: Listing of multiple project names
167+
Given I have a "NativeCurlClient" client
168+
And I create "108" projects
169+
When I list all project names
170+
Then the response has the status code "200"
171+
And the response has the content type "application/json"
172+
And the returned data contains "108" items
173+
153174
Scenario: Updating a project
154175
Given I have a "NativeCurlClient" client
155176
And I create a project with name "Test Project" and identifier "test-project"

0 commit comments

Comments
 (0)