Skip to content

Commit

Permalink
Add IssueStatus::list() method, deprecate all() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Oct 9, 2023
1 parent 4e5cc67 commit bf61171
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 4 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/kbsali/php-redmine-api/compare/v2.3.0...v2.x)

## [v2.3.0](https://github.com/kbsali/php-redmine-api/compare/v2.2.0...v2.3.0) - 2023-10-09

### Added

- New method `Redmine\Api\CustomField::list()` to list custom fields.
Expand All @@ -17,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New method `Redmine\Api\IssueCategory::list()` to list issue categories.
- New method `Redmine\Api\IssuePriority::list()` to list issue priorities.
- New method `Redmine\Api\IssueRelation::list()` to list issue relations.
- New method `Redmine\Api\IssueStatus::list()` to list issue statuses.

### Deprecated

Expand All @@ -26,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Redmine\Api\IssueCategory::all()` is deprecated, use `Redmine\Api\IssueCategory::list()` instead
- `Redmine\Api\IssuePriority::all()` is deprecated, use `Redmine\Api\IssuePriority::list()` instead
- `Redmine\Api\IssueRelation::all()` is deprecated, use `Redmine\Api\IssueRelation::list()` instead
- `Redmine\Api\IssueStatus::all()` is deprecated, use `Redmine\Api\IssueStatus::list()` instead

## [v2.3.0](https://github.com/kbsali/php-redmine-api/compare/v2.2.0...v2.3.0) - 2023-10-09

### Added

Expand Down
22 changes: 20 additions & 2 deletions src/Redmine/Api/IssueStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,31 @@ class IssueStatus extends AbstractApi
*
* @return array list of issue statuses found
*/
public function all(array $params = [])
final public function list(array $params = []): array
{
$this->issueStatuses = $this->retrieveData('/issue_statuses.json', $params);

return $this->issueStatuses;
}

/**
* List issue statuses.
*
* @deprecated since v2.4.0, use list() instead.
*
* @see http://www.redmine.org/projects/redmine/wiki/Rest_IssueStatuses#GET
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @return array list of issue statuses found
*/
public function all(array $params = [])
{
@trigger_error('`'.__METHOD__.'()` is deprecated since v2.4.0, use `'.__CLASS__.'::list()` instead.', E_USER_DEPRECATED);

return $this->list($params);
}

/**
* Returns an array of issue statuses with name/id pairs.
*
Expand All @@ -39,7 +57,7 @@ public function all(array $params = [])
public function listing($forceUpdate = false)
{
if (empty($this->issueStatuses) || $forceUpdate) {
$this->all();
$this->list();
}
$ret = [];
foreach ($this->issueStatuses['issue_statuses'] as $e) {
Expand Down
79 changes: 79 additions & 0 deletions tests/Unit/Api/IssueStatus/ListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Redmine\Tests\Unit\Api\IssueStatus;

use PHPUnit\Framework\TestCase;
use Redmine\Api\IssueStatus;
use Redmine\Client\Client;

/**
* Tests for IssueStatus::list()
*/
class ListTest extends TestCase
{
/**
* @covers \Redmine\Api\IssueStatus::list
*/
public function testListWithoutParametersReturnsResponse()
{
// Test values
$response = '["API Response"]';
$expectedReturn = ['API Response'];

// Create the used mock objects
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('requestGet')
->with(
$this->stringStartsWith('/issue_statuses.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 IssueStatus($client);

// Perform the tests
$this->assertSame($expectedReturn, $api->list());
}

/**
* @covers \Redmine\Api\IssueStatus::list
*/
public function testListWithParametersReturnsResponse()
{
// Test values
$parameters = ['not-used'];
$response = '["API Response"]';
$expectedReturn = ['API Response'];

// Create the used mock objects
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('requestGet')
->with(
$this->logicalAnd(
$this->stringStartsWith('/issue_statuses.json'),
$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 IssueStatus($client);

// Perform the tests
$this->assertSame($expectedReturn, $api->list($parameters));
}
}
27 changes: 27 additions & 0 deletions tests/Unit/Api/IssueStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\TestCase;
use Redmine\Api\IssueStatus;
use Redmine\Client\Client;
use Redmine\Tests\Fixtures\MockClient;

/**
* @coversDefaultClass \Redmine\Api\IssueStatus
Expand All @@ -13,6 +14,32 @@
*/
class IssueStatusTest extends TestCase
{
/**
* Test all().
*
* @covers ::all
*/
public function testAllTriggersDeprecationWarning()
{
$api = new IssueStatus(MockClient::create());

// PHPUnit 10 compatible way to test trigger_error().
set_error_handler(
function ($errno, $errstr): bool {
$this->assertSame(
'`Redmine\Api\IssueStatus::all()` is deprecated since v2.4.0, use `Redmine\Api\IssueStatus::list()` instead.',
$errstr
);

restore_error_handler();
return true;
},
E_USER_DEPRECATED
);

$api->all();
}

/**
* Test all().
*
Expand Down

0 comments on commit bf61171

Please sign in to comment.