-
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.
Add CustomFields::list(), deprecate all()
- Loading branch information
Showing
4 changed files
with
184 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
|
||
namespace Redmine\Tests\Unit\Api\CustomField; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Redmine\Api\CustomField; | ||
use Redmine\Client\Client; | ||
|
||
/** | ||
* Tests for CustomField::list() | ||
*/ | ||
class ListTest extends TestCase | ||
{ | ||
/** | ||
* @covers \Redmine\Api\CustomField::list | ||
* @covers \Redmine\Api\CustomField::get | ||
* @covers \Redmine\Api\CustomField::retrieveAll | ||
* @covers \Redmine\Api\CustomField::isNotNull | ||
*/ | ||
public function testListWithoutParametersReturnsResponse() | ||
{ | ||
// Test values | ||
$response = '["API Response"]'; | ||
$expectedResponse = ['API Response']; | ||
|
||
// Create the used mock objects | ||
$client = $this->createMock(Client::class); | ||
$client->expects($this->once()) | ||
->method('requestGet') | ||
->with( | ||
$this->stringStartsWith('/custom_fields.json') | ||
) | ||
->willReturn(true); | ||
$client->expects($this->exactly(1)) | ||
->method('getLastResponseBody') | ||
->willReturn($response); | ||
$client->expects($this->exactly(1)) | ||
->method('getLastResponseContentType') | ||
->willReturn('application/json'); | ||
|
||
// Create the object under test | ||
$api = new CustomField($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedResponse, $api->list()); | ||
} | ||
|
||
/** | ||
* @covers \Redmine\Api\CustomField::list | ||
* @covers \Redmine\Api\CustomField::get | ||
* @covers \Redmine\Api\CustomField::retrieveAll | ||
* @covers \Redmine\Api\CustomField::isNotNull | ||
*/ | ||
public function testListWithParametersReturnsResponse() | ||
{ | ||
// Test values | ||
$allParameters = ['not-used']; | ||
$response = '["API Response"]'; | ||
$expectedResponse = ['API Response']; | ||
|
||
// Create the used mock objects | ||
$client = $this->createMock(Client::class); | ||
$client->expects($this->once()) | ||
->method('requestGet') | ||
->with( | ||
$this->stringContains('not-used') | ||
) | ||
->willReturn(true); | ||
$client->expects($this->exactly(1)) | ||
->method('getLastResponseBody') | ||
->willReturn($response); | ||
$client->expects($this->exactly(1)) | ||
->method('getLastResponseContentType') | ||
->willReturn('application/json'); | ||
|
||
// Create the object under test | ||
$api = new CustomField($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedResponse, $api->list($allParameters)); | ||
} | ||
|
||
/** | ||
* @covers \Redmine\Api\CustomField::list | ||
* @covers \Redmine\Api\CustomField::get | ||
* @covers \Redmine\Api\CustomField::retrieveAll | ||
* @covers \Redmine\Api\CustomField::isNotNull | ||
*/ | ||
public function testListWithHighLimitParametersReturnsResponse() | ||
{ | ||
// Test values | ||
$response = '{"limit":"100","items":[]}'; | ||
$allParameters = ['limit' => 250]; | ||
$expectedResponse = [ | ||
'limit' => ['100', '100', '100'], // TODO: Check response created by array_merge_recursive() | ||
'items' => [], | ||
]; | ||
|
||
// Create the used mock objects | ||
$client = $this->createMock(Client::class); | ||
$client->expects($this->exactly(3)) | ||
->method('requestGet') | ||
->with( | ||
$this->stringStartsWith('/custom_fields.json') | ||
) | ||
->willReturn(true); | ||
$client->expects($this->exactly(3)) | ||
->method('getLastResponseBody') | ||
->willReturn($response); | ||
$client->expects($this->exactly(3)) | ||
->method('getLastResponseContentType') | ||
->willReturn('application/json'); | ||
|
||
// Create the object under test | ||
$api = new CustomField($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedResponse, $api->list($allParameters)); | ||
} | ||
|
||
/** | ||
* Test list(). | ||
* | ||
* @covers \Redmine\Api\CustomField::list | ||
* @covers \Redmine\Api\CustomField::get | ||
* @covers \Redmine\Api\CustomField::retrieveAll | ||
* @covers \Redmine\Api\CustomField::isNotNull | ||
*/ | ||
public function testListCallsEndpointUntilOffsetIsHigherThanTotalCount() | ||
{ | ||
// Test values | ||
$response = '{"limit":"100","offset":"10","total_count":"5","items":[]}'; | ||
$allParameters = ['limit' => 250]; | ||
$returnDataSet = [ | ||
'limit' => '100', | ||
'offset' => '10', | ||
'total_count' => '5', | ||
'items' => [], | ||
]; | ||
|
||
// Create the used mock objects | ||
$client = $this->createMock(Client::class); | ||
$client->expects($this->once()) | ||
->method('requestGet') | ||
->with( | ||
$this->stringStartsWith('/custom_fields.json') | ||
) | ||
->willReturn(true); | ||
$client->expects($this->exactly(1)) | ||
->method('getLastResponseBody') | ||
->willReturn($response); | ||
$client->expects($this->exactly(1)) | ||
->method('getLastResponseContentType') | ||
->willReturn('application/json'); | ||
|
||
// Create the object under test | ||
$api = new CustomField($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($returnDataSet, $api->list($allParameters)); | ||
} | ||
} |
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