From bf61171f985f8546b68e8518de04f71921dec66c Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 9 Oct 2023 13:10:05 +0200 Subject: [PATCH] Add IssueStatus::list() method, deprecate all() method --- CHANGELOG.md | 6 +- src/Redmine/Api/IssueStatus.php | 22 ++++++- tests/Unit/Api/IssueStatus/ListTest.php | 79 +++++++++++++++++++++++++ tests/Unit/Api/IssueStatusTest.php | 27 +++++++++ 4 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 tests/Unit/Api/IssueStatus/ListTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7293650e..868333c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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 @@ -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 diff --git a/src/Redmine/Api/IssueStatus.php b/src/Redmine/Api/IssueStatus.php index 6c6f776a..bcb68eea 100644 --- a/src/Redmine/Api/IssueStatus.php +++ b/src/Redmine/Api/IssueStatus.php @@ -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. * @@ -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) { diff --git a/tests/Unit/Api/IssueStatus/ListTest.php b/tests/Unit/Api/IssueStatus/ListTest.php new file mode 100644 index 00000000..1dc874da --- /dev/null +++ b/tests/Unit/Api/IssueStatus/ListTest.php @@ -0,0 +1,79 @@ +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)); + } +} diff --git a/tests/Unit/Api/IssueStatusTest.php b/tests/Unit/Api/IssueStatusTest.php index ac812ac0..4e795b1e 100644 --- a/tests/Unit/Api/IssueStatusTest.php +++ b/tests/Unit/Api/IssueStatusTest.php @@ -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 @@ -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(). *