From f29d8b26e869181a8ada4e9fc91da47f0214160a Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 09:42:53 +0200 Subject: [PATCH 1/8] improve tests to make clear the listed group names are sorted by id instead of names --- tests/Behat/features/groups.feature | 20 ++++++++++---------- tests/Unit/Api/Group/ListNamesTest.php | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Behat/features/groups.feature b/tests/Behat/features/groups.feature index ec72b9c5..cbd77bc3 100644 --- a/tests/Behat/features/groups.feature +++ b/tests/Behat/features/groups.feature @@ -60,11 +60,11 @@ Feature: Interacting with the REST API for groups @group Scenario: Listing names of all groups Given I have a "NativeCurlClient" client - And I create a group with name "Test Group 1" - And I create a group with name "Test Group 2" - And I create a group with name "Test Group 3" - And I create a group with name "Test Group 4" - And I create a group with name "Test Group 5" + And I create a group with name "Test Group D" + And I create a group with name "Test Group E" + And I create a group with name "Test Group C" + And I create a group with name "Test Group B" + And I create a group with name "Test Group A" When I list the names of all groups Then the response has the status code "200" And the response has the content type "application/json" @@ -72,11 +72,11 @@ Feature: Interacting with the REST API for groups And the returned data contains "5" items And the returned data contains the following data | property | value | - | 4 | Test Group 1 | - | 5 | Test Group 2 | - | 6 | Test Group 3 | - | 7 | Test Group 4 | - | 8 | Test Group 5 | + | 4 | Test Group D | + | 5 | Test Group E | + | 6 | Test Group C | + | 7 | Test Group B | + | 8 | Test Group A | @group Scenario: Showing a specific group diff --git a/tests/Unit/Api/Group/ListNamesTest.php b/tests/Unit/Api/Group/ListNamesTest.php index 39829d98..55c0d990 100644 --- a/tests/Unit/Api/Group/ListNamesTest.php +++ b/tests/Unit/Api/Group/ListNamesTest.php @@ -58,16 +58,16 @@ public static function getListNamesData(): array << "Group 1", - 8 => "Group 2", 7 => "Group 3", + 8 => "Group 2", + 9 => "Group 1", ], ], ]; From 030ae2b63d57afb5c7d2171273b88f76228af564 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 10:31:29 +0200 Subject: [PATCH 2/8] Add behat tests for list issue categories --- .../Bootstrap/IssueCategoryContextTrait.php | 14 ++++ tests/Behat/features/issue_category.feature | 69 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/tests/Behat/Bootstrap/IssueCategoryContextTrait.php b/tests/Behat/Bootstrap/IssueCategoryContextTrait.php index 7352e1d8..073c9611 100644 --- a/tests/Behat/Bootstrap/IssueCategoryContextTrait.php +++ b/tests/Behat/Bootstrap/IssueCategoryContextTrait.php @@ -29,6 +29,20 @@ public function iCreateAnIssueCategoryForProjectIdentifierAndWithTheFollowingDat ); } + /** + * @When I list all issue categories for project identifier :identifier + */ + public function iListAllIssueCategoriesForProjectIdentifier($identifier) + { + /** @var IssueCategory */ + $api = $this->getNativeCurlClient()->getApi('issue_category'); + + $this->registerClientResponse( + $api->listByProject($identifier), + $api->getLastResponse(), + ); + } + /** * @When I update the issue category with id :id and the following data */ diff --git a/tests/Behat/features/issue_category.feature b/tests/Behat/features/issue_category.feature index 3f1c068c..027e0342 100644 --- a/tests/Behat/features/issue_category.feature +++ b/tests/Behat/features/issue_category.feature @@ -83,6 +83,75 @@ Feature: Interacting with the REST API for issue categories | id | 1 | | name | Redmine Admin | + Scenario: Listing of zero issue categories + Given I have a "NativeCurlClient" client + And I create a project with name "Test Project" and identifier "test-project" + When I list all issue categories for project identifier "test-project" + 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 + """ + issue_categories + total_count + """ + And the returned data contains the following data + | property | value | + | issue_categories | [] | + | total_count | 0 | + + Scenario: Listing of multiple issue categories + Given I have a "NativeCurlClient" client + And I create a project with name "Test Project" and identifier "test-project" + And I create an issue category for project identifier "test-project" and with the following data + | property | value | + | name | Category name B | + And I create an issue category for project identifier "test-project" and with the following data + | property | value | + | name | Category name A | + When I list all issue categories for project identifier "test-project" + 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 + """ + issue_categories + total_count + """ + And the returned data contains the following data + | property | value | + | total_count | 2 | + And the returned data "issue_categories" property is an array + And the returned data "issue_categories" property contains "2" items + And the returned data "issue_categories.0" property is an array + And the returned data "issue_categories.0" property has only the following properties + """ + id + project + name + """ + And the returned data "issue_categories.0" property contains the following data + | property | value | + | id | 2 | + | name | Category name A | + And the returned data "issue_categories.0.project" property contains the following data + | property | value | + | id | 1 | + | name | Test Project | + And the returned data "issue_categories.1" property is an array + And the returned data "issue_categories.1" property has only the following properties + """ + id + project + name + """ + And the returned data "issue_categories.1" property contains the following data + | property | value | + | id | 1 | + | name | Category name B | + And the returned data "issue_categories.1.project" property contains the following data + | property | value | + | id | 1 | + | name | Test Project | + @issue_category Scenario: Updating an issue category with all data Given I have a "NativeCurlClient" client From 3bd9db6d06a171380dc7a7e2c28c530a0481077b Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 11:46:24 +0200 Subject: [PATCH 3/8] implement IssueCategory::listNamesByProject() --- src/Redmine/Api/IssueCategory.php | 37 +++++ .../Bootstrap/IssueCategoryContextTrait.php | 14 ++ tests/Behat/features/issue_category.feature | 17 +++ .../IssueCategory/ListNamesByProjectTest.php | 139 ++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php diff --git a/src/Redmine/Api/IssueCategory.php b/src/Redmine/Api/IssueCategory.php index 864040d8..fdf53624 100644 --- a/src/Redmine/Api/IssueCategory.php +++ b/src/Redmine/Api/IssueCategory.php @@ -24,6 +24,8 @@ class IssueCategory extends AbstractApi { private $issueCategories = []; + private $issueCategoriesNames = []; + /** * List issue categories for a given project. * @@ -53,6 +55,41 @@ final public function listByProject($projectIdentifier, array $params = []): arr } } + /** + * Returns an array of all issue categories by a project with id/name pairs. + * + * @param string|int $projectIdentifier project id or literal identifier + * + * @throws InvalidParameterException if $projectIdentifier is not of type int or string + * + * @return array list of issue category names (id => name) + */ + final public function listNamesByProject($projectIdentifier): array + { + if (! is_int($projectIdentifier) && ! is_string($projectIdentifier)) { + throw new InvalidParameterException(sprintf( + '%s(): Argument #1 ($projectIdentifier) must be of type int or string', + __METHOD__, + )); + } + + if (array_key_exists($projectIdentifier, $this->issueCategoriesNames)) { + return $this->issueCategoriesNames[$projectIdentifier]; + } + + $this->issueCategoriesNames[$projectIdentifier] = []; + + $list = $this->listByProject($projectIdentifier); + + if (array_key_exists('issue_categories', $list)) { + foreach ($list['issue_categories'] as $category) { + $this->issueCategoriesNames[$projectIdentifier][(int) $category['id']] = $category['name']; + } + } + + return $this->issueCategoriesNames[$projectIdentifier]; + } + /** * List issue categories. * diff --git a/tests/Behat/Bootstrap/IssueCategoryContextTrait.php b/tests/Behat/Bootstrap/IssueCategoryContextTrait.php index 073c9611..36dfd24c 100644 --- a/tests/Behat/Bootstrap/IssueCategoryContextTrait.php +++ b/tests/Behat/Bootstrap/IssueCategoryContextTrait.php @@ -43,6 +43,20 @@ public function iListAllIssueCategoriesForProjectIdentifier($identifier) ); } + /** + * @When I list all issue category names for project identifier :identifier + */ + public function iListAllIssueCategoryNamesForProjectIdentifier($identifier) + { + /** @var IssueCategory */ + $api = $this->getNativeCurlClient()->getApi('issue_category'); + + $this->registerClientResponse( + $api->listNamesByProject($identifier), + $api->getLastResponse(), + ); + } + /** * @When I update the issue category with id :id and the following data */ diff --git a/tests/Behat/features/issue_category.feature b/tests/Behat/features/issue_category.feature index 027e0342..df4ff42a 100644 --- a/tests/Behat/features/issue_category.feature +++ b/tests/Behat/features/issue_category.feature @@ -152,6 +152,23 @@ Feature: Interacting with the REST API for issue categories | id | 1 | | name | Test Project | + Scenario: Listing of multiple issue category names + Given I have a "NativeCurlClient" client + And I create a project with name "Test Project" and identifier "test-project" + And I create an issue category for project identifier "test-project" and with the following data + | property | value | + | name | Category name B | + And I create an issue category for project identifier "test-project" and with the following data + | property | value | + | name | Category name A | + When I list all issue category names for project identifier "test-project" + Then the response has the status code "200" + And the response has the content type "application/json" + And the returned data contains the following data + | property | value | + | 1 | Category name B | + | 2 | Category name A | + @issue_category Scenario: Updating an issue category with all data Given I have a "NativeCurlClient" client diff --git a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php new file mode 100644 index 00000000..9357147d --- /dev/null +++ b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php @@ -0,0 +1,139 @@ +assertSame($expectedResponse, $api->listNamesByProject($projectIdentifier)); + } + + public static function getListNamesByProjectData(): array + { + return [ + 'test without issue categories' => [ + 5, + '/projects/5/issue_categories.json', + 201, + << [ + 'test-project', + '/projects/test-project/issue_categories.json', + 201, + << "IssueCategory 1", + 8 => "IssueCategory 2", + 7 => "IssueCategory 3", + ], + ], + ]; + } + + public function testListNamesByProjectCallsHttpClientOnlyOnce() + { + $client = AssertingHttpClient::create( + $this, + [ + 'GET', + '/projects/5/issue_categories.json', + 'application/json', + '', + 200, + 'application/json', + <<assertSame([1 => 'IssueCategory 1'], $api->listNamesByProject(5)); + $this->assertSame([1 => 'IssueCategory 1'], $api->listNamesByProject(5)); + $this->assertSame([1 => 'IssueCategory 1'], $api->listNamesByProject(5)); + } + + /** + * @dataProvider getInvalidProjectIdentifiers + */ + #[DataProvider('getInvalidProjectIdentifiers')] + public function testListNamesByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) + { + $api = new IssueCategory($this->createMock(HttpClient::class)); + + $this->expectException(InvalidParameterException::class); + $this->expectExceptionMessage('Redmine\Api\IssueCategory::listNamesByProject(): Argument #1 ($projectIdentifier) must be of type int or string'); + + $api->listNamesByProject($projectIdentifier); + } + + public static function getInvalidProjectIdentifiers(): array + { + return [ + 'null' => [null], + 'true' => [true], + 'false' => [false], + 'float' => [0.0], + 'array' => [[]], + 'object' => [new stdClass()], + ]; + } +} From 8194bd1c09ac35d8ad155e880994dfbc6767412f Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 15:31:17 +0200 Subject: [PATCH 4/8] Deprecate IssueCategory::listing() --- src/Redmine/Api/IssueCategory.php | 5 +++++ tests/Unit/Api/IssueCategoryTest.php | 32 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Redmine/Api/IssueCategory.php b/src/Redmine/Api/IssueCategory.php index fdf53624..3bf1a671 100644 --- a/src/Redmine/Api/IssueCategory.php +++ b/src/Redmine/Api/IssueCategory.php @@ -125,6 +125,9 @@ public function all($project, array $params = []) /** * Returns an array of categories with name/id pairs. * + * @deprecated v2.7.0 Use listNamesByProject() instead. + * @see Group::listNames() + * * @param string|int $project project id or literal identifier * @param bool $forceUpdate to force the update of the projects var * @@ -132,6 +135,8 @@ public function all($project, array $params = []) */ public function listing($project, $forceUpdate = false) { + @trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNamesByProject()` instead.', E_USER_DEPRECATED); + if (true === $forceUpdate || empty($this->issueCategories)) { $this->issueCategories = $this->listByProject($project); } diff --git a/tests/Unit/Api/IssueCategoryTest.php b/tests/Unit/Api/IssueCategoryTest.php index 26156bae..5c011f2d 100644 --- a/tests/Unit/Api/IssueCategoryTest.php +++ b/tests/Unit/Api/IssueCategoryTest.php @@ -219,6 +219,38 @@ public function testListingCallsGetEveryTimeWithForceUpdate() $this->assertSame($expectedReturn, $api->listing(5, true)); } + /** + * Test listing(). + */ + public function testListingTriggersDeprecationWarning() + { + $client = $this->createMock(Client::class); + $client->method('requestGet') + ->willReturn(true); + $client->method('getLastResponseBody') + ->willReturn('{"issue_categories":[{"id":1,"name":"IssueCategory 1"},{"id":5,"name":"IssueCategory 5"}]}'); + $client->method('getLastResponseContentType') + ->willReturn('application/json'); + + $api = new IssueCategory($client); + + // PHPUnit 10 compatible way to test trigger_error(). + set_error_handler( + function ($errno, $errstr): bool { + $this->assertSame( + '`Redmine\Api\IssueCategory::listing()` is deprecated since v2.7.0, use `Redmine\Api\IssueCategory::listNamesByProject()` instead.', + $errstr, + ); + + restore_error_handler(); + return true; + }, + E_USER_DEPRECATED, + ); + + $api->listing(5); + } + /** * Test getIdByName(). */ From 3a216e8ae3b442620632e63ca993bf095cb1b3bc Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 15:32:27 +0200 Subject: [PATCH 5/8] Improve tests, update CHANGELOG.md --- CHANGELOG.md | 2 ++ tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab9803b7..016b9651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New method `Redmine\Api\Group::listNames()` for listing the ids and names of all groups. +- New method `Redmine\Api\IssueCategory::listNamesByProject()` for listing the ids and names of all issue categories of a project. ### Deprecated - `Redmine\Api\Group::listing()` is deprecated, use `\Redmine\Api\Group::listNames()` instead. +- `Redmine\Api\IssueCategory::listing()` is deprecated, use `\Redmine\Api\IssueCategory::listNamesByProject()` instead. ## [v2.6.0](https://github.com/kbsali/php-redmine-api/compare/v2.5.0...v2.6.0) - 2024-03-25 diff --git a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php index 9357147d..1c5b4160 100644 --- a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php +++ b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php @@ -63,16 +63,16 @@ public static function getListNamesByProjectData(): array << "IssueCategory 1", - 8 => "IssueCategory 2", 7 => "IssueCategory 3", + 8 => "IssueCategory 2", + 9 => "IssueCategory 1", ], ], ]; From d8284750554ecf78fb65cb8a17cf2391ad2e63a6 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 15:35:19 +0200 Subject: [PATCH 6/8] Fix comment --- src/Redmine/Api/IssueCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redmine/Api/IssueCategory.php b/src/Redmine/Api/IssueCategory.php index 3bf1a671..25a05eb9 100644 --- a/src/Redmine/Api/IssueCategory.php +++ b/src/Redmine/Api/IssueCategory.php @@ -126,7 +126,7 @@ public function all($project, array $params = []) * Returns an array of categories with name/id pairs. * * @deprecated v2.7.0 Use listNamesByProject() instead. - * @see Group::listNames() + * @see IssueCategory::listNamesByProject() * * @param string|int $project project id or literal identifier * @param bool $forceUpdate to force the update of the projects var From d0b720fb7232f8841f77d1d29002931e3fe507d9 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 16:05:20 +0200 Subject: [PATCH 7/8] Move DataProvider into own class --- tests/Fixtures/TestDataProvider.php | 22 +++++++++++++++++++ .../IssueCategory/ListNamesByProjectTest.php | 19 ++++------------ 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 tests/Fixtures/TestDataProvider.php diff --git a/tests/Fixtures/TestDataProvider.php b/tests/Fixtures/TestDataProvider.php new file mode 100644 index 00000000..3db9b173 --- /dev/null +++ b/tests/Fixtures/TestDataProvider.php @@ -0,0 +1,22 @@ + [null], + 'true' => [true], + 'false' => [false], + 'float' => [0.0], + 'array' => [[]], + 'object' => [new stdClass()], + ]; + } +} diff --git a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php index 1c5b4160..3ec124d1 100644 --- a/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php +++ b/tests/Unit/Api/IssueCategory/ListNamesByProjectTest.php @@ -6,12 +6,13 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Redmine\Api\IssueCategory; use Redmine\Exception\InvalidParameterException; use Redmine\Http\HttpClient; use Redmine\Tests\Fixtures\AssertingHttpClient; -use stdClass; +use Redmine\Tests\Fixtures\TestDataProvider; #[CoversClass(IssueCategory::class)] class ListNamesByProjectTest extends TestCase @@ -112,9 +113,9 @@ public function testListNamesByProjectCallsHttpClientOnlyOnce() } /** - * @dataProvider getInvalidProjectIdentifiers + * @dataProvider Redmine\Tests\Fixtures\TestDataProvider::getInvalidProjectIdentifiers */ - #[DataProvider('getInvalidProjectIdentifiers')] + #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListNamesByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) { $api = new IssueCategory($this->createMock(HttpClient::class)); @@ -124,16 +125,4 @@ public function testListNamesByProjectWithWrongProjectIdentifierThrowsException( $api->listNamesByProject($projectIdentifier); } - - public static function getInvalidProjectIdentifiers(): array - { - return [ - 'null' => [null], - 'true' => [true], - 'false' => [false], - 'float' => [0.0], - 'array' => [[]], - 'object' => [new stdClass()], - ]; - } } From 92da0f0524b43f703692fc69b173b8eaff192274 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 27 Jun 2024 16:22:26 +0200 Subject: [PATCH 8/8] update all tests with invalid project identifiers --- .../Api/IssueCategory/ListByProjectTest.php | 20 ++++--------------- .../Unit/Api/Membership/ListByProjectTest.php | 20 ++++--------------- tests/Unit/Api/News/ListByProjectTest.php | 20 ++++--------------- tests/Unit/Api/Version/ListByProjectTest.php | 20 ++++--------------- tests/Unit/Api/Wiki/ListByProjectTest.php | 20 ++++--------------- 5 files changed, 20 insertions(+), 80 deletions(-) diff --git a/tests/Unit/Api/IssueCategory/ListByProjectTest.php b/tests/Unit/Api/IssueCategory/ListByProjectTest.php index 52a0b920..a3592ed1 100644 --- a/tests/Unit/Api/IssueCategory/ListByProjectTest.php +++ b/tests/Unit/Api/IssueCategory/ListByProjectTest.php @@ -3,14 +3,14 @@ namespace Redmine\Tests\Unit\Api\IssueCategory; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Redmine\Api\IssueCategory; use Redmine\Client\Client; use Redmine\Exception\InvalidParameterException; use Redmine\Exception\UnexpectedResponseException; use Redmine\Tests\Fixtures\MockClient; -use stdClass; +use Redmine\Tests\Fixtures\TestDataProvider; #[CoversClass(IssueCategory::class)] class ListByProjectTest extends TestCase @@ -71,9 +71,9 @@ public function testListByProjectWithParametersReturnsResponse() } /** - * @dataProvider getInvalidProjectIdentifiers + * @dataProvider Redmine\Tests\Fixtures\TestDataProvider::getInvalidProjectIdentifiers */ - #[DataProvider('getInvalidProjectIdentifiers')] + #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) { $api = new IssueCategory(MockClient::create()); @@ -84,18 +84,6 @@ public function testListByProjectWithWrongProjectIdentifierThrowsException($proj $api->listByProject($projectIdentifier); } - public static function getInvalidProjectIdentifiers(): array - { - return [ - 'null' => [null], - 'true' => [true], - 'false' => [false], - 'float' => [0.0], - 'array' => [[]], - 'object' => [new stdClass()], - ]; - } - public function testListByProjectThrowsException() { // Create the used mock objects diff --git a/tests/Unit/Api/Membership/ListByProjectTest.php b/tests/Unit/Api/Membership/ListByProjectTest.php index c6c4483d..c877e0b0 100644 --- a/tests/Unit/Api/Membership/ListByProjectTest.php +++ b/tests/Unit/Api/Membership/ListByProjectTest.php @@ -3,14 +3,14 @@ namespace Redmine\Tests\Unit\Api\Membership; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Redmine\Api\Membership; use Redmine\Client\Client; use Redmine\Exception\InvalidParameterException; use Redmine\Exception\UnexpectedResponseException; use Redmine\Tests\Fixtures\MockClient; -use stdClass; +use Redmine\Tests\Fixtures\TestDataProvider; #[CoversClass(Membership::class)] class ListByProjectTest extends TestCase @@ -69,9 +69,9 @@ public function testListByProjectWithParametersReturnsResponse() } /** - * @dataProvider getInvalidProjectIdentifiers + * @dataProvider Redmine\Tests\Fixtures\TestDataProvider::getInvalidProjectIdentifiers */ - #[DataProvider('getInvalidProjectIdentifiers')] + #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) { $api = new Membership(MockClient::create()); @@ -82,18 +82,6 @@ public function testListByProjectWithWrongProjectIdentifierThrowsException($proj $api->listByProject($projectIdentifier); } - public static function getInvalidProjectIdentifiers(): array - { - return [ - 'null' => [null], - 'true' => [true], - 'false' => [false], - 'float' => [0.0], - 'array' => [[]], - 'object' => [new stdClass()], - ]; - } - public function testListByProjectThrowsException() { // Create the used mock objects diff --git a/tests/Unit/Api/News/ListByProjectTest.php b/tests/Unit/Api/News/ListByProjectTest.php index 4fa4db83..61009a6e 100644 --- a/tests/Unit/Api/News/ListByProjectTest.php +++ b/tests/Unit/Api/News/ListByProjectTest.php @@ -3,14 +3,14 @@ namespace Redmine\Tests\Unit\Api\News; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Redmine\Api\News; use Redmine\Client\Client; use Redmine\Exception\InvalidParameterException; use Redmine\Exception\UnexpectedResponseException; use Redmine\Tests\Fixtures\MockClient; -use stdClass; +use Redmine\Tests\Fixtures\TestDataProvider; #[CoversClass(News::class)] class ListByProjectTest extends TestCase @@ -71,9 +71,9 @@ public function testListByProjectWithParametersReturnsResponse() } /** - * @dataProvider getInvalidProjectIdentifiers + * @dataProvider Redmine\Tests\Fixtures\TestDataProvider::getInvalidProjectIdentifiers */ - #[DataProvider('getInvalidProjectIdentifiers')] + #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) { $api = new News(MockClient::create()); @@ -84,18 +84,6 @@ public function testListByProjectWithWrongProjectIdentifierThrowsException($proj $api->listByProject($projectIdentifier); } - public static function getInvalidProjectIdentifiers(): array - { - return [ - 'null' => [null], - 'true' => [true], - 'false' => [false], - 'float' => [0.0], - 'array' => [[]], - 'object' => [new stdClass()], - ]; - } - public function testListByProjectThrowsException() { // Create the used mock objects diff --git a/tests/Unit/Api/Version/ListByProjectTest.php b/tests/Unit/Api/Version/ListByProjectTest.php index d993f65d..7d6e3171 100644 --- a/tests/Unit/Api/Version/ListByProjectTest.php +++ b/tests/Unit/Api/Version/ListByProjectTest.php @@ -3,14 +3,14 @@ namespace Redmine\Tests\Unit\Api\Version; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Redmine\Api\Version; use Redmine\Client\Client; use Redmine\Exception\InvalidParameterException; use Redmine\Exception\UnexpectedResponseException; use Redmine\Tests\Fixtures\MockClient; -use stdClass; +use Redmine\Tests\Fixtures\TestDataProvider; #[CoversClass(Version::class)] class ListByProjectTest extends TestCase @@ -72,9 +72,9 @@ public function testListByProjectWithParametersReturnsResponse() } /** - * @dataProvider getInvalidProjectIdentifiers + * @dataProvider Redmine\Tests\Fixtures\TestDataProvider::getInvalidProjectIdentifiers */ - #[DataProvider('getInvalidProjectIdentifiers')] + #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) { $api = new Version(MockClient::create()); @@ -85,18 +85,6 @@ public function testListByProjectWithWrongProjectIdentifierThrowsException($proj $api->listByProject($projectIdentifier); } - public static function getInvalidProjectIdentifiers(): array - { - return [ - 'null' => [null], - 'true' => [true], - 'false' => [false], - 'float' => [0.0], - 'array' => [[]], - 'object' => [new stdClass()], - ]; - } - public function testListByProjectThrowsException() { // Create the used mock objects diff --git a/tests/Unit/Api/Wiki/ListByProjectTest.php b/tests/Unit/Api/Wiki/ListByProjectTest.php index 31381a22..43bd53eb 100644 --- a/tests/Unit/Api/Wiki/ListByProjectTest.php +++ b/tests/Unit/Api/Wiki/ListByProjectTest.php @@ -3,14 +3,14 @@ namespace Redmine\Tests\Unit\Api\Wiki; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Redmine\Api\Wiki; use Redmine\Client\Client; use Redmine\Exception\InvalidParameterException; use Redmine\Exception\UnexpectedResponseException; use Redmine\Tests\Fixtures\MockClient; -use stdClass; +use Redmine\Tests\Fixtures\TestDataProvider; #[CoversClass(Wiki::class)] class ListByProjectTest extends TestCase @@ -72,9 +72,9 @@ public function testListByProjectWithParametersReturnsResponse() } /** - * @dataProvider getInvalidProjectIdentifiers + * @dataProvider Redmine\Tests\Fixtures\TestDataProvider::getInvalidProjectIdentifiers */ - #[DataProvider('getInvalidProjectIdentifiers')] + #[DataProviderExternal(TestDataProvider::class, 'getInvalidProjectIdentifiers')] public function testListByProjectWithWrongProjectIdentifierThrowsException($projectIdentifier) { $api = new Wiki(MockClient::create()); @@ -85,18 +85,6 @@ public function testListByProjectWithWrongProjectIdentifierThrowsException($proj $api->listByProject($projectIdentifier); } - public static function getInvalidProjectIdentifiers(): array - { - return [ - 'null' => [null], - 'true' => [true], - 'false' => [false], - 'float' => [0.0], - 'array' => [[]], - 'object' => [new stdClass()], - ]; - } - public function testListByProjectThrowsException() { // Create the used mock objects