-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #409 from Art4/add-issuestatus-listnames
Add `IssueStatus::listNames()` method as replacement for `IssueStatus::listing()`
- Loading branch information
Showing
6 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
@issue_status | ||
Feature: Interacting with the REST API for issue statuses | ||
In order to interact with REST API for issue statuses | ||
As a user | ||
I want to make sure the Redmine server replies with the correct response | ||
|
||
Scenario: Listing of zero issue statuses | ||
Given I have a "NativeCurlClient" client | ||
When I list all issue statuses | ||
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 | ||
""" | ||
issue_statuses | ||
""" | ||
And the returned data "issue_statuses" property is an array | ||
And the returned data "issue_statuses" property contains "0" items | ||
|
||
Scenario: Listing of multiple issue statuses | ||
Given I have a "NativeCurlClient" client | ||
And I have an issue status with the name "New" | ||
And I have an issue status with the name "Done" | ||
When I list all issue statuses | ||
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 | ||
""" | ||
issue_statuses | ||
""" | ||
And the returned data "issue_statuses" property is an array | ||
And the returned data "issue_statuses" property contains "2" items | ||
# field 'description' was added in Redmine 5.1.0, see https://www.redmine.org/issues/2568 | ||
And the returned data "issue_statuses.0" property contains the following data with Redmine version ">= 5.1.0" | ||
| property | value | | ||
| id | 1 | | ||
| name | New | | ||
| is_closed | false | | ||
| description | null | | ||
But the returned data "issue_statuses.0" property contains the following data with Redmine version "< 5.1.0" | ||
| property | value | | ||
| id | 1 | | ||
| name | New | | ||
| is_closed | false | | ||
# field 'description' was added in Redmine 5.1.0, see https://www.redmine.org/issues/2568 | ||
And the returned data "issue_statuses.1" property contains the following data with Redmine version ">= 5.1.0" | ||
| property | value | | ||
| id | 2 | | ||
| name | Done | | ||
| is_closed | false | | ||
| description | null | | ||
But the returned data "issue_statuses.1" property contains the following data with Redmine version "< 5.1.0" | ||
| property | value | | ||
| id | 2 | | ||
| name | Done | | ||
| is_closed | false | | ||
|
||
Scenario: Listing of multiple issue status names | ||
Given I have a "NativeCurlClient" client | ||
And I have an issue status with the name "New" | ||
And I have an issue status with the name "Done" | ||
When I list all issue status 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 | New | | ||
| 2 | Done | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Redmine\Tests\Unit\Api\IssueStatus; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Redmine\Api\IssueStatus; | ||
use Redmine\Tests\Fixtures\AssertingHttpClient; | ||
|
||
#[CoversClass(IssueStatus::class)] | ||
class ListNamesTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider getListNamesData | ||
*/ | ||
#[DataProvider('getListNamesData')] | ||
public function testListNamesReturnsCorrectResponse($expectedPath, $responseCode, $response, $expectedResponse) | ||
{ | ||
$client = AssertingHttpClient::create( | ||
$this, | ||
[ | ||
'GET', | ||
$expectedPath, | ||
'application/json', | ||
'', | ||
$responseCode, | ||
'application/json', | ||
$response, | ||
], | ||
); | ||
|
||
// Create the object under test | ||
$api = new IssueStatus($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedResponse, $api->listNames()); | ||
} | ||
|
||
public static function getListNamesData(): array | ||
{ | ||
return [ | ||
'test without issue statuses' => [ | ||
'/issue_statuses.json', | ||
201, | ||
<<<JSON | ||
{ | ||
"issue_statuses": [] | ||
} | ||
JSON, | ||
[], | ||
], | ||
'test with multiple issue statuses' => [ | ||
'/issue_statuses.json', | ||
201, | ||
<<<JSON | ||
{ | ||
"issue_statuses": [ | ||
{"id": 7, "name": "IssueStatus C"}, | ||
{"id": 8, "name": "IssueStatus B"}, | ||
{"id": 9, "name": "IssueStatus A"} | ||
] | ||
} | ||
JSON, | ||
[ | ||
7 => "IssueStatus C", | ||
8 => "IssueStatus B", | ||
9 => "IssueStatus A", | ||
], | ||
], | ||
]; | ||
} | ||
|
||
public function testListNamesCallsHttpClientOnlyOnce() | ||
{ | ||
$client = AssertingHttpClient::create( | ||
$this, | ||
[ | ||
'GET', | ||
'/issue_statuses.json', | ||
'application/json', | ||
'', | ||
200, | ||
'application/json', | ||
<<<JSON | ||
{ | ||
"issue_statuses": [ | ||
{ | ||
"id": 1, | ||
"name": "IssueStatus 1" | ||
} | ||
] | ||
} | ||
JSON, | ||
], | ||
); | ||
|
||
// Create the object under test | ||
$api = new IssueStatus($client); | ||
|
||
// Perform the tests | ||
$this->assertSame([1 => 'IssueStatus 1'], $api->listNames()); | ||
$this->assertSame([1 => 'IssueStatus 1'], $api->listNames()); | ||
$this->assertSame([1 => 'IssueStatus 1'], $api->listNames()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters