Skip to content

Commit ecf0012

Browse files
authored
Merge pull request #414 from Art4/add-timeentryactivity-listnames
Add `TimeEntryActivity::listNames()` method as replacement for `TimeEntryActivity::listing()`
2 parents 097ac2e + 7161d27 commit ecf0012

File tree

9 files changed

+301
-21
lines changed

9 files changed

+301
-21
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- New method `Redmine\Api\IssueStatus::listNames()` for listing the ids and names of all issue statuses.
1616
- New method `Redmine\Api\Project::listNames()` for listing the ids and names of all projects.
1717
- New method `Redmine\Api\Role::listNames()` for listing the ids and names of all roles.
18+
- New method `Redmine\Api\TimeEntryActivity::listNames()` for listing the ids and names of all time entry activities.
1819

1920
### Deprecated
2021

2122
- `Redmine\Api\CustomField::listing()` is deprecated, use `\Redmine\Api\CustomField::listNames()` instead.
2223
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
2324
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
24-
- `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.
26-
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNamesByProject()` instead.
25+
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNames()` instead.
26+
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
27+
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
28+
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.
2729

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

src/Redmine/Api/TimeEntryActivity.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class TimeEntryActivity extends AbstractApi
1717
{
1818
private $timeEntryActivities = [];
1919

20+
private $timeEntryActivityNames = null;
21+
2022
/**
2123
* List time entry activities.
2224
*
@@ -35,6 +37,29 @@ final public function list(array $params = []): array
3537
}
3638
}
3739

40+
/**
41+
* Returns an array of all time entry activities with id/name pairs.
42+
*
43+
* @return array<int,string> list of time entry activities (id => name)
44+
*/
45+
final public function listNames(): array
46+
{
47+
if ($this->timeEntryActivityNames !== null) {
48+
return $this->timeEntryActivityNames;
49+
}
50+
51+
$this->timeEntryActivityNames = [];
52+
$list = $this->list();
53+
54+
if (array_key_exists('time_entry_activities', $list)) {
55+
foreach ($list['time_entry_activities'] as $activity) {
56+
$this->timeEntryActivityNames[(int) $activity['id']] = $activity['name'];
57+
}
58+
}
59+
60+
return $this->timeEntryActivityNames;
61+
}
62+
3863
/**
3964
* List time entry activities.
4065
*
@@ -69,12 +94,17 @@ public function all(array $params = [])
6994
/**
7095
* Returns an array of time entry activities with name/id pairs.
7196
*
97+
* @deprecated v2.7.0 Use listNames() instead.
98+
* @see TimeEntryActivity::listNames()
99+
*
72100
* @param bool $forceUpdate to force the update of the statuses var
73101
*
74102
* @return array list of time entry activities (id => name)
75103
*/
76104
public function listing($forceUpdate = false)
77105
{
106+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
107+
78108
if (empty($this->timeEntryActivities) || $forceUpdate) {
79109
$this->timeEntryActivities = $this->list();
80110
}

tests/Behat/Bootstrap/TimeEntryActivityContextTrait.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Redmine\Tests\Behat\Bootstrap;
66

7+
use Redmine\Api\TimeEntryActivity;
8+
79
trait TimeEntryActivityContextTrait
810
{
911
/**
@@ -18,10 +20,38 @@ public function iHaveATimeEntryActiviyWithName(string $activityName)
1820
[
1921
':name' => $activityName,
2022
':position' => 1,
21-
':is_default' => 1,
23+
':is_default' => 0,
2224
':type' => 'TimeEntryActivity',
2325
':active' => 1,
2426
],
2527
);
2628
}
29+
30+
/**
31+
* @When I list all time entry activities
32+
*/
33+
public function iListAllTimeEntryActivities()
34+
{
35+
/** @var TimeEntryActivity */
36+
$api = $this->getNativeCurlClient()->getApi('time_entry_activity');
37+
38+
$this->registerClientResponse(
39+
$api->list(),
40+
$api->getLastResponse(),
41+
);
42+
}
43+
44+
/**
45+
* @When I list all time entry activity names
46+
*/
47+
public function iListAllTimeEntryActivityNames()
48+
{
49+
/** @var TimeEntryActivity */
50+
$api = $this->getNativeCurlClient()->getApi('time_entry_activity');
51+
52+
$this->registerClientResponse(
53+
$api->listNames(),
54+
$api->getLastResponse(),
55+
);
56+
}
2757
}

tests/Behat/features/groups.feature

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Feature: Interacting with the REST API for groups
1717
"""
1818
And the returned data has proterties with the following data
1919
| property | value |
20-
| id | 4 |
20+
| id | 5 |
2121
| name | Test Group |
2222

2323
Scenario: Listing of zero groups
@@ -52,7 +52,7 @@ Feature: Interacting with the REST API for groups
5252
"""
5353
And the returned data "groups.0" property contains the following data
5454
| property | value |
55-
| id | 4 |
55+
| id | 5 |
5656
| name | Test Group |
5757

5858
Scenario: Listing names of all groups
@@ -69,16 +69,16 @@ Feature: Interacting with the REST API for groups
6969
And the returned data contains "5" items
7070
And the returned data contains the following data
7171
| property | value |
72-
| 4 | Test Group D |
73-
| 5 | Test Group E |
74-
| 6 | Test Group C |
75-
| 7 | Test Group B |
76-
| 8 | Test Group A |
72+
| 5 | Test Group D |
73+
| 6 | Test Group E |
74+
| 7 | Test Group C |
75+
| 8 | Test Group B |
76+
| 9 | Test Group A |
7777

7878
Scenario: Showing a specific group
7979
Given I have a "NativeCurlClient" client
8080
And I create a group with name "Test Group"
81-
When I show the group with id "4"
81+
When I show the group with id "5"
8282
Then the response has the status code "200"
8383
And the response has the content type "application/json"
8484
And the returned data has only the following properties
@@ -93,7 +93,7 @@ Feature: Interacting with the REST API for groups
9393
"""
9494
And the returned data "group" property contains the following data
9595
| property | value |
96-
| id | 4 |
96+
| id | 5 |
9797
| name | Test Group |
9898

9999
@error
@@ -110,7 +110,7 @@ Feature: Interacting with the REST API for groups
110110
And I create a group with the following data
111111
| property | value |
112112
| name | Test Group |
113-
When I update the group with id "4" with the following data
113+
When I update the group with id "5" with the following data
114114
| property | value |
115115
| name | new group name |
116116
Then the response has the status code "204"
@@ -121,7 +121,7 @@ Feature: Interacting with the REST API for groups
121121
Scenario: Adding an user to a group
122122
Given I have a "NativeCurlClient" client
123123
And I create a group with name "Test Group"
124-
When I add the user with id "1" to the group with id "4"
124+
When I add the user with id "1" to the group with id "5"
125125
Then the response has the status code "204"
126126
And the response has an empty content type
127127
And the response has the content ""
@@ -130,8 +130,8 @@ Feature: Interacting with the REST API for groups
130130
Scenario: Removing an user from a group
131131
Given I have a "NativeCurlClient" client
132132
And I create a group with name "Test Group"
133-
And I add the user with id "1" to the group with id "4"
134-
When I remove the user with id "1" from the group with id "4"
133+
And I add the user with id "1" to the group with id "5"
134+
When I remove the user with id "1" from the group with id "5"
135135
Then the response has the status code "204"
136136
And the response has an empty content type
137137
And the response has the content ""
@@ -140,7 +140,7 @@ Feature: Interacting with the REST API for groups
140140
Scenario: Deleting a group
141141
Given I have a "NativeCurlClient" client
142142
And I create a group with name "Test Group"
143-
When I remove the group with id "4"
143+
When I remove the group with id "5"
144144
Then the response has the status code "204"
145145
And the response has an empty content type
146146
And the response has the content ""

tests/Behat/features/time_entry.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Feature: Interacting with the REST API for time_entries
1212
| property | value |
1313
| project_id | 1 |
1414
| hours | 1 |
15+
| activity_id | 1 |
1516
Then the response has the status code "201"
1617
And the response has the content type "application/xml"
1718
And the returned data is an instance of "SimpleXMLElement"
@@ -77,6 +78,7 @@ Feature: Interacting with the REST API for time_entries
7778
| property | value |
7879
| project_id | 1 |
7980
| hours | 1 |
81+
| activity_id | 1 |
8082
When I update the time entry with id "1" and the following data
8183
| property | value |
8284
| project_id | 1 |
@@ -94,6 +96,7 @@ Feature: Interacting with the REST API for time_entries
9496
| property | value |
9597
| project_id | 1 |
9698
| hours | 1 |
99+
| activity_id | 1 |
97100
When I show the time entry with the id "1"
98101
Then the response has the status code "200"
99102
And the response has the content type "application/json"
@@ -168,6 +171,7 @@ Feature: Interacting with the REST API for time_entries
168171
| property | value |
169172
| project_id | 1 |
170173
| hours | 1 |
174+
| activity_id | 1 |
171175
When I remove the time entry with id "1"
172176
Then the response has the status code "204"
173177
And the response has an empty content type
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@time_entry_activity
2+
Feature: Interacting with the REST API for time entry activities
3+
In order to interact with REST API for time entry activities
4+
As a user
5+
I want to make sure the Redmine server replies with the correct response
6+
7+
Scenario: Listing of zero time entry activities
8+
Given I have a "NativeCurlClient" client
9+
When I list all time entry activities
10+
Then the response has the status code "200"
11+
And the response has the content type "application/json"
12+
And the returned data has only the following properties
13+
"""
14+
time_entry_activities
15+
"""
16+
And the returned data "time_entry_activities" property is an array
17+
And the returned data "time_entry_activities" property contains "0" items
18+
19+
Scenario: Listing of multiple time entry activities
20+
Given I have a "NativeCurlClient" client
21+
And I have a time entry activiy with name "Development"
22+
And I have a time entry activiy with name "Support"
23+
When I list all time entry activities
24+
Then the response has the status code "200"
25+
And the response has the content type "application/json"
26+
And the returned data has only the following properties
27+
"""
28+
time_entry_activities
29+
"""
30+
And the returned data "time_entry_activities" property is an array
31+
And the returned data "time_entry_activities" property contains "2" items
32+
And the returned data "time_entry_activities.0" property is an array
33+
And the returned data "time_entry_activities.0" property has only the following properties
34+
"""
35+
id
36+
name
37+
is_default
38+
active
39+
"""
40+
And the returned data "time_entry_activities.0" property contains the following data
41+
| property | value |
42+
| id | 1 |
43+
| name | Development |
44+
| is_default | false |
45+
| active | true |
46+
And the returned data "time_entry_activities.1" property is an array
47+
And the returned data "time_entry_activities.1" property has only the following properties
48+
"""
49+
id
50+
name
51+
is_default
52+
active
53+
"""
54+
And the returned data "time_entry_activities.1" property contains the following data
55+
| property | value |
56+
| id | 2 |
57+
| name | Support |
58+
| is_default | false |
59+
| active | true |
60+
61+
Scenario: Listing of multiple time entry activity names
62+
Given I have a "NativeCurlClient" client
63+
And I have a time entry activiy with name "Development"
64+
And I have a time entry activiy with name "Support"
65+
When I list all time entry activity names
66+
Then the response has the status code "200"
67+
And the response has the content type "application/json"
68+
And the returned data is an array
69+
And the returned data contains "2" items
70+
And the returned data contains the following data
71+
| property | value |
72+
| 1 | Development |
73+
| 2 | Support |
74+

tests/Behat/features/user.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Feature: Interacting with the REST API for users
3434
"""
3535
And the returned data has proterties with the following data
3636
| property | value |
37-
| id | 4 |
37+
| id | 5 |
3838
| login | username |
3939
| admin | false |
4040
| firstname | first |
@@ -53,7 +53,7 @@ Feature: Interacting with the REST API for users
5353
| firstname | first |
5454
| lastname | last |
5555
| mail | mail@example.com |
56-
When I update the user with id "4" and the following data
56+
When I update the user with id "5" and the following data
5757
| property | value |
5858
| firstname | new_first |
5959
| lastname | new_last |
@@ -121,7 +121,7 @@ Feature: Interacting with the REST API for users
121121
| firstname | first |
122122
| lastname | last |
123123
| mail | mail@example.com |
124-
When I remove the user with id "4"
124+
When I remove the user with id "5"
125125
Then the response has the status code "204"
126126
And the response has an empty content type
127127
And the response has the content ""

0 commit comments

Comments
 (0)