forked from kbsali/php-redmine-api
-
Notifications
You must be signed in to change notification settings - Fork 0
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 kbsali#412 from Art4/add-role-listnames
Add `Role::listNames()` method as replacement for `Role::listing()`
- Loading branch information
Showing
6 changed files
with
257 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,55 @@ | ||
@role | ||
Feature: Interacting with the REST API for roles | ||
In order to interact with REST API for roles | ||
As a user | ||
I want to make sure the Redmine server replies with the correct response | ||
|
||
Scenario: Listing of zero roles | ||
Given I have a "NativeCurlClient" client | ||
When I list all roles | ||
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 | ||
""" | ||
roles | ||
""" | ||
And the returned data "roles" property is an array | ||
And the returned data "roles" property contains "0" items | ||
|
||
Scenario: Listing of multiple roles | ||
Given I have a "NativeCurlClient" client | ||
And I have a role with the name "Reporter" | ||
And I have a role with the name "Developer" | ||
When I list all roles | ||
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 | ||
""" | ||
roles | ||
""" | ||
And the returned data "roles" property is an array | ||
And the returned data "roles" property contains "2" items | ||
And the returned data "roles.0" property contains "2" items | ||
And the returned data "roles.0" property contains the following data | ||
| property | value | | ||
| id | 3 | | ||
| name | Reporter | | ||
And the returned data "roles.1" property contains "2" items | ||
And the returned data "roles.1" property contains the following data | ||
| property | value | | ||
| id | 4 | | ||
| name | Developer | | ||
|
||
Scenario: Listing of multiple role names | ||
Given I have a "NativeCurlClient" client | ||
And I have a role with the name "Reporter" | ||
And I have a role with the name "Developer" | ||
When I list all role 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 | | ||
| 3 | Reporter | | ||
| 4 | Developer | |
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\Role; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Redmine\Api\Role; | ||
use Redmine\Tests\Fixtures\AssertingHttpClient; | ||
|
||
#[CoversClass(Role::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 Role($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedResponse, $api->listNames()); | ||
} | ||
|
||
public static function getListNamesData(): array | ||
{ | ||
return [ | ||
'test without roles' => [ | ||
'/roles.json', | ||
201, | ||
<<<JSON | ||
{ | ||
"roles": [] | ||
} | ||
JSON, | ||
[], | ||
], | ||
'test with multiple roles' => [ | ||
'/roles.json', | ||
201, | ||
<<<JSON | ||
{ | ||
"roles": [ | ||
{"id": 7, "name": "Role 3"}, | ||
{"id": 8, "name": "Role 2"}, | ||
{"id": 9, "name": "Role 1"} | ||
] | ||
} | ||
JSON, | ||
[ | ||
7 => "Role 3", | ||
8 => "Role 2", | ||
9 => "Role 1", | ||
], | ||
], | ||
]; | ||
} | ||
|
||
public function testListNamesCallsHttpClientOnlyOnce() | ||
{ | ||
$client = AssertingHttpClient::create( | ||
$this, | ||
[ | ||
'GET', | ||
'/roles.json', | ||
'application/json', | ||
'', | ||
200, | ||
'application/json', | ||
<<<JSON | ||
{ | ||
"roles": [ | ||
{ | ||
"id": 1, | ||
"name": "Role 1" | ||
} | ||
] | ||
} | ||
JSON, | ||
], | ||
); | ||
|
||
// Create the object under test | ||
$api = new Role($client); | ||
|
||
// Perform the tests | ||
$this->assertSame([1 => 'Role 1'], $api->listNames()); | ||
$this->assertSame([1 => 'Role 1'], $api->listNames()); | ||
$this->assertSame([1 => 'Role 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