Skip to content

Commit

Permalink
Merge pull request #414 from Art4/add-timeentryactivity-listnames
Browse files Browse the repository at this point in the history
Add `TimeEntryActivity::listNames()` method as replacement for `TimeEntryActivity::listing()`
  • Loading branch information
Art4 authored Jul 5, 2024
2 parents 097ac2e + 7161d27 commit ecf0012
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 21 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New method `Redmine\Api\IssueStatus::listNames()` for listing the ids and names of all issue statuses.
- New method `Redmine\Api\Project::listNames()` for listing the ids and names of all projects.
- New method `Redmine\Api\Role::listNames()` for listing the ids and names of all roles.
- New method `Redmine\Api\TimeEntryActivity::listNames()` for listing the ids and names of all time entry activities.

### Deprecated

- `Redmine\Api\CustomField::listing()` is deprecated, use `\Redmine\Api\CustomField::listNames()` instead.
- `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead.
- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead.
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNamesByProject()` instead.
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNamesByProject()` instead.
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNamesByProject()` instead.
- `Redmine\Api\IssueStatus::listing()` is deprecated, use `\Redmine\Api\IssueStatus::listNames()` instead.
- `Redmine\Api\Project::listing()` is deprecated, use `\Redmine\Api\Project::listNames()` instead.
- `Redmine\Api\Role::listing()` is deprecated, use `\Redmine\Api\Role::listNames()` instead.
- `Redmine\Api\TimeEntryActivity::listing()` is deprecated, use `\Redmine\Api\TimeEntryActivity::listNames()` instead.

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

Expand Down
30 changes: 30 additions & 0 deletions src/Redmine/Api/TimeEntryActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TimeEntryActivity extends AbstractApi
{
private $timeEntryActivities = [];

private $timeEntryActivityNames = null;

/**
* List time entry activities.
*
Expand All @@ -35,6 +37,29 @@ final public function list(array $params = []): array
}
}

/**
* Returns an array of all time entry activities with id/name pairs.
*
* @return array<int,string> list of time entry activities (id => name)
*/
final public function listNames(): array
{
if ($this->timeEntryActivityNames !== null) {
return $this->timeEntryActivityNames;
}

$this->timeEntryActivityNames = [];
$list = $this->list();

if (array_key_exists('time_entry_activities', $list)) {
foreach ($list['time_entry_activities'] as $activity) {
$this->timeEntryActivityNames[(int) $activity['id']] = $activity['name'];
}
}

return $this->timeEntryActivityNames;
}

/**
* List time entry activities.
*
Expand Down Expand Up @@ -69,12 +94,17 @@ public function all(array $params = [])
/**
* Returns an array of time entry activities with name/id pairs.
*
* @deprecated v2.7.0 Use listNames() instead.
* @see TimeEntryActivity::listNames()
*
* @param bool $forceUpdate to force the update of the statuses var
*
* @return array list of time entry activities (id => name)
*/
public function listing($forceUpdate = false)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);

if (empty($this->timeEntryActivities) || $forceUpdate) {
$this->timeEntryActivities = $this->list();
}
Expand Down
32 changes: 31 additions & 1 deletion tests/Behat/Bootstrap/TimeEntryActivityContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Redmine\Tests\Behat\Bootstrap;

use Redmine\Api\TimeEntryActivity;

trait TimeEntryActivityContextTrait
{
/**
Expand All @@ -18,10 +20,38 @@ public function iHaveATimeEntryActiviyWithName(string $activityName)
[
':name' => $activityName,
':position' => 1,
':is_default' => 1,
':is_default' => 0,
':type' => 'TimeEntryActivity',
':active' => 1,
],
);
}

/**
* @When I list all time entry activities
*/
public function iListAllTimeEntryActivities()
{
/** @var TimeEntryActivity */
$api = $this->getNativeCurlClient()->getApi('time_entry_activity');

$this->registerClientResponse(
$api->list(),
$api->getLastResponse(),
);
}

/**
* @When I list all time entry activity names
*/
public function iListAllTimeEntryActivityNames()
{
/** @var TimeEntryActivity */
$api = $this->getNativeCurlClient()->getApi('time_entry_activity');

$this->registerClientResponse(
$api->listNames(),
$api->getLastResponse(),
);
}
}
28 changes: 14 additions & 14 deletions tests/Behat/features/groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Interacting with the REST API for groups
"""
And the returned data has proterties with the following data
| property | value |
| id | 4 |
| id | 5 |
| name | Test Group |

Scenario: Listing of zero groups
Expand Down Expand Up @@ -52,7 +52,7 @@ Feature: Interacting with the REST API for groups
"""
And the returned data "groups.0" property contains the following data
| property | value |
| id | 4 |
| id | 5 |
| name | Test Group |

Scenario: Listing names of all groups
Expand All @@ -69,16 +69,16 @@ Feature: Interacting with the REST API for groups
And the returned data contains "5" items
And the returned data contains the following data
| property | value |
| 4 | Test Group D |
| 5 | Test Group E |
| 6 | Test Group C |
| 7 | Test Group B |
| 8 | Test Group A |
| 5 | Test Group D |
| 6 | Test Group E |
| 7 | Test Group C |
| 8 | Test Group B |
| 9 | Test Group A |

Scenario: Showing a specific group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
When I show the group with id "4"
When I show the group with id "5"
Then the response has the status code "200"
And the response has the content type "application/json"
And the returned data has only the following properties
Expand All @@ -93,7 +93,7 @@ Feature: Interacting with the REST API for groups
"""
And the returned data "group" property contains the following data
| property | value |
| id | 4 |
| id | 5 |
| name | Test Group |

@error
Expand All @@ -110,7 +110,7 @@ Feature: Interacting with the REST API for groups
And I create a group with the following data
| property | value |
| name | Test Group |
When I update the group with id "4" with the following data
When I update the group with id "5" with the following data
| property | value |
| name | new group name |
Then the response has the status code "204"
Expand All @@ -121,7 +121,7 @@ Feature: Interacting with the REST API for groups
Scenario: Adding an user to a group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
When I add the user with id "1" to the group with id "4"
When I add the user with id "1" to the group with id "5"
Then the response has the status code "204"
And the response has an empty content type
And the response has the content ""
Expand All @@ -130,8 +130,8 @@ Feature: Interacting with the REST API for groups
Scenario: Removing an user from a group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
And I add the user with id "1" to the group with id "4"
When I remove the user with id "1" from the group with id "4"
And I add the user with id "1" to the group with id "5"
When I remove the user with id "1" from the group with id "5"
Then the response has the status code "204"
And the response has an empty content type
And the response has the content ""
Expand All @@ -140,7 +140,7 @@ Feature: Interacting with the REST API for groups
Scenario: Deleting a group
Given I have a "NativeCurlClient" client
And I create a group with name "Test Group"
When I remove the group with id "4"
When I remove the group with id "5"
Then the response has the status code "204"
And the response has an empty content type
And the response has the content ""
Expand Down
4 changes: 4 additions & 0 deletions tests/Behat/features/time_entry.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Interacting with the REST API for time_entries
| property | value |
| project_id | 1 |
| hours | 1 |
| activity_id | 1 |
Then the response has the status code "201"
And the response has the content type "application/xml"
And the returned data is an instance of "SimpleXMLElement"
Expand Down Expand Up @@ -77,6 +78,7 @@ Feature: Interacting with the REST API for time_entries
| property | value |
| project_id | 1 |
| hours | 1 |
| activity_id | 1 |
When I update the time entry with id "1" and the following data
| property | value |
| project_id | 1 |
Expand All @@ -94,6 +96,7 @@ Feature: Interacting with the REST API for time_entries
| property | value |
| project_id | 1 |
| hours | 1 |
| activity_id | 1 |
When I show the time entry with the id "1"
Then the response has the status code "200"
And the response has the content type "application/json"
Expand Down Expand Up @@ -168,6 +171,7 @@ Feature: Interacting with the REST API for time_entries
| property | value |
| project_id | 1 |
| hours | 1 |
| activity_id | 1 |
When I remove the time entry with id "1"
Then the response has the status code "204"
And the response has an empty content type
Expand Down
74 changes: 74 additions & 0 deletions tests/Behat/features/time_entry_activity.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@time_entry_activity
Feature: Interacting with the REST API for time entry activities
In order to interact with REST API for time entry activities
As a user
I want to make sure the Redmine server replies with the correct response

Scenario: Listing of zero time entry activities
Given I have a "NativeCurlClient" client
When I list all time entry activities
Then the response has the status code "200"
And the response has the content type "application/json"
And the returned data has only the following properties
"""
time_entry_activities
"""
And the returned data "time_entry_activities" property is an array
And the returned data "time_entry_activities" property contains "0" items

Scenario: Listing of multiple time entry activities
Given I have a "NativeCurlClient" client
And I have a time entry activiy with name "Development"
And I have a time entry activiy with name "Support"
When I list all time entry activities
Then the response has the status code "200"
And the response has the content type "application/json"
And the returned data has only the following properties
"""
time_entry_activities
"""
And the returned data "time_entry_activities" property is an array
And the returned data "time_entry_activities" property contains "2" items
And the returned data "time_entry_activities.0" property is an array
And the returned data "time_entry_activities.0" property has only the following properties
"""
id
name
is_default
active
"""
And the returned data "time_entry_activities.0" property contains the following data
| property | value |
| id | 1 |
| name | Development |
| is_default | false |
| active | true |
And the returned data "time_entry_activities.1" property is an array
And the returned data "time_entry_activities.1" property has only the following properties
"""
id
name
is_default
active
"""
And the returned data "time_entry_activities.1" property contains the following data
| property | value |
| id | 2 |
| name | Support |
| is_default | false |
| active | true |

Scenario: Listing of multiple time entry activity names
Given I have a "NativeCurlClient" client
And I have a time entry activiy with name "Development"
And I have a time entry activiy with name "Support"
When I list all time entry activity names
Then the response has the status code "200"
And the response has the content type "application/json"
And the returned data is an array
And the returned data contains "2" items
And the returned data contains the following data
| property | value |
| 1 | Development |
| 2 | Support |

6 changes: 3 additions & 3 deletions tests/Behat/features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Feature: Interacting with the REST API for users
"""
And the returned data has proterties with the following data
| property | value |
| id | 4 |
| id | 5 |
| login | username |
| admin | false |
| firstname | first |
Expand All @@ -53,7 +53,7 @@ Feature: Interacting with the REST API for users
| firstname | first |
| lastname | last |
| mail | mail@example.com |
When I update the user with id "4" and the following data
When I update the user with id "5" and the following data
| property | value |
| firstname | new_first |
| lastname | new_last |
Expand Down Expand Up @@ -121,7 +121,7 @@ Feature: Interacting with the REST API for users
| firstname | first |
| lastname | last |
| mail | mail@example.com |
When I remove the user with id "4"
When I remove the user with id "5"
Then the response has the status code "204"
And the response has an empty content type
And the response has the content ""
Expand Down
Loading

0 comments on commit ecf0012

Please sign in to comment.