-
Notifications
You must be signed in to change notification settings - Fork 182
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 #398 from Art4/338-replace-listing-methods-with-co…
…nsistent-solution Add `Group::listNames()` method as replacement for `Group::listing()`
- Loading branch information
Showing
7 changed files
with
293 additions
and
48 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
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,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Redmine\Tests\Unit\Api\Group; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Redmine\Api\Group; | ||
use Redmine\Tests\Fixtures\AssertingHttpClient; | ||
|
||
#[CoversClass(Group::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 Group($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedResponse, $api->listNames()); | ||
} | ||
|
||
public static function getListNamesData(): array | ||
{ | ||
return [ | ||
'test without groups' => [ | ||
'/groups.json', | ||
201, | ||
<<<JSON | ||
{ | ||
"groups": [] | ||
} | ||
JSON, | ||
[] | ||
], | ||
'test with multiple groups' => [ | ||
'/groups.json', | ||
201, | ||
<<<JSON | ||
{ | ||
"groups": [ | ||
{"id": 9, "name": "Group 1"}, | ||
{"id": 8, "name": "Group 2"}, | ||
{"id": 7, "name": "Group 3"} | ||
] | ||
} | ||
JSON, | ||
[ | ||
9 => "Group 1", | ||
8 => "Group 2", | ||
7 => "Group 3", | ||
] | ||
], | ||
]; | ||
} | ||
|
||
public function testListNamesCallsHttpClientOnlyOnce() | ||
{ | ||
$client = AssertingHttpClient::create( | ||
$this, | ||
[ | ||
'GET', | ||
'/groups.json', | ||
'application/json', | ||
'', | ||
200, | ||
'application/json', | ||
<<<JSON | ||
{ | ||
"groups": [ | ||
{ | ||
"id": 1, | ||
"name": "Group 1" | ||
} | ||
] | ||
} | ||
JSON, | ||
] | ||
); | ||
|
||
// Create the object under test | ||
$api = new Group($client); | ||
|
||
// Perform the tests | ||
$this->assertSame([1 => 'Group 1'], $api->listNames()); | ||
$this->assertSame([1 => 'Group 1'], $api->listNames()); | ||
$this->assertSame([1 => 'Group 1'], $api->listNames()); | ||
} | ||
} |
Oops, something went wrong.