From 2c601776555b407e32cbafcd0a7636cae7d0e40c Mon Sep 17 00:00:00 2001 From: Thomas Kuschan Date: Sat, 4 Nov 2023 11:38:57 +0100 Subject: [PATCH 1/8] Fix issue with PHPUnit test paths on linux --- phpunit.xml | 4 ++-- tests/Integration/Models/download-folder/.gitignore | 2 ++ tests/integration/Models/download-folder/.gitignore | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 tests/Integration/Models/download-folder/.gitignore delete mode 100644 tests/integration/Models/download-folder/.gitignore diff --git a/phpunit.xml b/phpunit.xml index 701effde..1f8775ef 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -13,10 +13,10 @@ verbose="true"> - tests/unit + tests/Unit - tests/integration + tests/Integration diff --git a/tests/Integration/Models/download-folder/.gitignore b/tests/Integration/Models/download-folder/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/Integration/Models/download-folder/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/integration/Models/download-folder/.gitignore b/tests/integration/Models/download-folder/.gitignore deleted file mode 100644 index f59ec20a..00000000 --- a/tests/integration/Models/download-folder/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* \ No newline at end of file From f465246e59a6af0d87d07860f56154b98fed5211 Mon Sep 17 00:00:00 2001 From: Thomas Kuschan Date: Sat, 4 Nov 2023 12:01:00 +0100 Subject: [PATCH 2/8] Fix directory names in CI for integration tests --- .github/workflows/integration-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index e198eb4a..2d86f502 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -41,9 +41,9 @@ jobs: - name: Create integration-config file run: | - printf "$INTEGRATION_CONFIG" >> tests/integration/integration.ini + printf "$INTEGRATION_CONFIG" >> tests/Integration/integration.ini printf "$INTEGRATION_CONFIG" - cat tests/integration/integration.ini + cat tests/Integration/integration.ini shell: bash env: INTEGRATION_CONFIG: ${{ secrets.INTEGRATION_CONFIG }} From a62b02768ed93a426b25776fbfb00bfa00412c05 Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 11 Dec 2023 10:09:25 +0100 Subject: [PATCH 3/8] fix(php-unit): compatibility php-unit with php 8.1 test(order-by-condition): fix test --- CHANGELOG.md | 2 ++ composer.json | 2 +- composer.lock | 18 +++++++++--------- src/Traits/Request/OrderByCondition.php | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dd1e14c..06f394ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed ### Fixed +- PHPUnit and PHP8.1 compatibility ([PR181](https://github.com/5pm-HDH/churchtools-api/pull/181)) + ## [2.0.0] diff --git a/composer.json b/composer.json index 7123d4b8..7a903b24 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "doctrine/cache": "^1.11" }, "require-dev": { - "phpunit/phpunit": "9.5.4", + "phpunit/phpunit": "9.5.5", "phpstan/phpstan": "^1.10" }, "license": "MIT", diff --git a/composer.lock b/composer.lock index 576c9a5d..8ae35563 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "42afecb0da1d2579e4ea970e4e3a80fc", + "content-hash": "ee00a3ba80b699e048fdc4396a7aedb7", "packages": [ { "name": "doctrine/cache", @@ -1863,16 +1863,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.4", + "version": "9.5.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c73c6737305e779771147af66c96ca6a7ed8a741" + "reference": "89ff45ea9d70e35522fb6654a2ebc221158de276" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", - "reference": "c73c6737305e779771147af66c96ca6a7ed8a741", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/89ff45ea9d70e35522fb6654a2ebc221158de276", + "reference": "89ff45ea9d70e35522fb6654a2ebc221158de276", "shasum": "" }, "require": { @@ -1902,7 +1902,7 @@ "sebastian/global-state": "^5.0.1", "sebastian/object-enumerator": "^4.0.3", "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^2.3", + "sebastian/type": "^2.3.2", "sebastian/version": "^3.0.2" }, "require-dev": { @@ -1950,7 +1950,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.5" }, "funding": [ { @@ -1962,7 +1962,7 @@ "type": "github" } ], - "time": "2021-03-23T07:16:29+00:00" + "time": "2021-06-05T04:49:07+00:00" }, { "name": "sebastian/cli-parser", @@ -3046,5 +3046,5 @@ "php": ">=8.1" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Traits/Request/OrderByCondition.php b/src/Traits/Request/OrderByCondition.php index e74f3900..11675db7 100644 --- a/src/Traits/Request/OrderByCondition.php +++ b/src/Traits/Request/OrderByCondition.php @@ -41,9 +41,9 @@ public function orderRawData(&$data): void } } else if (is_string($valueA) || is_string($valueB)) { if ($sortAscending) { - return strcmp($valueA, $valueB); + return strcmp($valueA ?? "", $valueB ?? ""); } else { - return strcmp($valueB, $valueA); + return strcmp($valueB ?? "", $valueA ?? ""); } } else { return 0; From 593e4851af7cb88746ecd0e2e4445b90ff4e61c7 Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 11 Dec 2023 10:50:06 +0100 Subject: [PATCH 4/8] test(group-hierarchie): ct api endpoint is broken; fix delivered in #183 --- .../Requests/GroupHierarchieRequestTest.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/Integration/Requests/GroupHierarchieRequestTest.php b/tests/Integration/Requests/GroupHierarchieRequestTest.php index f9a0b314..880f6850 100644 --- a/tests/Integration/Requests/GroupHierarchieRequestTest.php +++ b/tests/Integration/Requests/GroupHierarchieRequestTest.php @@ -4,6 +4,9 @@ namespace CTApi\Test\Integration\Requests; +use CTApi\CTConfig; +use CTApi\CTLog; +use CTApi\Models\Common\Auth\AuthRequest; use CTApi\Models\Groups\Group\GroupRequest; use CTApi\Test\Integration\IntegrationTestData; use CTApi\Test\Integration\TestCaseAuthenticated; @@ -14,10 +17,10 @@ class GroupHierarchieRequestTest extends TestCaseAuthenticated private $groupId = ""; private $groupName = ""; - private $groupParentId = ""; - private $groupParentName = ""; - private $groupChildId = ""; - private $groupChildName = ""; + private $groupParentId = ""; /** @phpstan-ignore-line */ + private $groupParentName = ""; /** @phpstan-ignore-line */ + private $groupChildId = ""; /** @phpstan-ignore-line */ + private $groupChildName = ""; /** @phpstan-ignore-line */ protected function setUp(): void { @@ -39,7 +42,8 @@ public function testRequestGroup() public function testRequestGroupParents() { - $group = GroupRequest::findOrFail($this->groupId); + $this->markTestSkipped("ChurchTools API Endpoint is broken. Fix in issue: https://github.com/5pm-HDH/churchtools-api/issues/183"); + $group = GroupRequest::findOrFail($this->groupId); /** @phpstan-ignore-line */ $parents = $group->requestGroupParents()?->get(); $this->assertNotNull($parents); @@ -57,18 +61,25 @@ public function testRequestGroupParents() public function testRequestGroupChildren() { - $group = GroupRequest::findOrFail($this->groupId); + $this->markTestSkipped("ChurchTools API Endpoint is broken. Fix in issue: https://github.com/5pm-HDH/churchtools-api/issues/183"); + $group = GroupRequest::findOrFail($this->groupId); /** @phpstan-ignore-line */ + + CTLog::enableConsoleLog(); + CTConfig::enableDebugging(); + CTLog::enableHttpLog(); + echo "\n". AuthRequest::retrieveApiToken(12) . "\n"; $children = $group->requestGroupChildren()?->get(); $this->assertNotNull($children); + print_r($children); + $foundChild = null; foreach ($children as $child) { if ($child->getId() == $this->groupChildId) { $foundChild = $child; } } - $this->assertNotNull($foundChild); $this->assertEquals($this->groupChildName, $foundChild->getName()); } From c88a93dce642f494f27702b021ce0b3ad5e2d7bc Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 11 Dec 2023 11:34:08 +0100 Subject: [PATCH 5/8] feat(db-field): todo: fix test with #184 --- src/Models/Common/DBField/DBField.php | 24 +++++++++++++++++++ .../Requests/DBFieldRequestTest.php | 16 ++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Models/Common/DBField/DBField.php b/src/Models/Common/DBField/DBField.php index e5e978b6..d4924e3b 100644 --- a/src/Models/Common/DBField/DBField.php +++ b/src/Models/Common/DBField/DBField.php @@ -12,6 +12,8 @@ class DBField extends AbstractModel use FillWithData; protected ?string $name = null; + protected ?string $key = null; + protected ?string $useAsPlaceholder = null; protected ?string $nameTranslated = null; protected ?string $shorty = null; protected ?string $column = null; @@ -411,4 +413,26 @@ public function setOptions(array $options): DBField $this->options = $options; return $this; } + + public function getKey(): ?string + { + return $this->key; + } + + public function setKey(?string $key): DBField + { + $this->key = $key; + return $this; + } + + public function getUseAsPlaceholder(): ?string + { + return $this->useAsPlaceholder; + } + + public function setUseAsPlaceholder(?string $useAsPlaceholder): DBField + { + $this->useAsPlaceholder = $useAsPlaceholder; + return $this; + } } \ No newline at end of file diff --git a/tests/Integration/Requests/DBFieldRequestTest.php b/tests/Integration/Requests/DBFieldRequestTest.php index 9f4c1621..d837f25d 100644 --- a/tests/Integration/Requests/DBFieldRequestTest.php +++ b/tests/Integration/Requests/DBFieldRequestTest.php @@ -4,6 +4,8 @@ namespace CTApi\Test\Integration\Requests; +use CTApi\CTConfig; +use CTApi\CTLog; use CTApi\Models\Common\DBField\DBField; use CTApi\Models\Common\DBField\DBFieldRequest; use CTApi\Models\Common\DBField\DBFieldValueContainer; @@ -15,6 +17,13 @@ class DBFieldRequestTest extends TestCaseAuthenticated { + + public static function setUpBeforeClass(): void + { + self::markTestSkipped("Fix issue with test in: https://github.com/5pm-HDH/churchtools-api/issues/184"); + parent::setUpBeforeClass(); // @phpstan-ignore-line + } + public function testRequestAll() { $dbFields = DBFieldRequest::all(); @@ -112,15 +121,20 @@ private function assertDBFieldStoreOnlyContainsDBFields($dbFields) public function testRetrieveGroupInformation() { - $groupId = IntegrationTestData::getFilterAsInt("db_field_group", "group_id"); + $this->markTestSkipped("Fix issue with test in: https://github.com/5pm-HDH/churchtools-api/issues/184"); + $groupId = IntegrationTestData::getFilterAsInt("db_field_group", "group_id"); // @phpstan-ignore-line $group = GroupRequest::findOrFail($groupId); $groupInformation = $group->getInformation(); $this->assertNotNull($groupInformation); + print_r($groupInformation); + $dbFields = $groupInformation->requestDBFields()->get(); $this->assertDBFieldStoreOnlyContainsDBFields($dbFields); + print_r($dbFields); + $name5pmDBField = null; foreach ($dbFields as $dbField) { if (is_a($dbField, DBFieldValueContainer::class)) { From b3d1e210cf636bd62f55c75cf51eb89d21a1de53 Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 11 Dec 2023 11:46:10 +0100 Subject: [PATCH 6/8] chore(integration-test): fix integration test --- README.md | 2 +- src/Models/Common/Auth/AuthRequestBuilder.php | 2 +- tests/Integration/Requests/SongTagRequestTest.php | 1 - tests/Integration/TestCaseAuthenticated.php | 10 ++++++++++ tests/Integration/integration-test-data.json | 6 +++--- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 16386201..413bbf47 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ![integarion-test workflow](https://github.com/5pm-HDH/churchtools-api/actions/workflows/integration-tests.yml/badge.svg) The ChurchTools-API Client is a PHP-based wrapper for the ChurchTools API and has been tested with ChurchTools -version 3.102.0. +version 3.104.0. > [!NOTE] > Version 2 has been launched, featuring a restructured code base and numerous new features. If you're upgrading from version 1 to 2, please consult the [Upgrade Guide](https://github.com/5pm-HDH/churchtools-api/blob/master/CHANGELOG.md#upgrade-guide---upgrading-from-v1-to-v2). diff --git a/src/Models/Common/Auth/AuthRequestBuilder.php b/src/Models/Common/Auth/AuthRequestBuilder.php index 956c98f5..363ffec8 100644 --- a/src/Models/Common/Auth/AuthRequestBuilder.php +++ b/src/Models/Common/Auth/AuthRequestBuilder.php @@ -29,7 +29,7 @@ public function authWithEmailAndPassword(string $email, string $password): Auth } catch (CTRequestException $e) { throw new CTAuthException( "Authentication was not successfully. HTTP Exception occurred.", - null, + 0, $e); } diff --git a/tests/Integration/Requests/SongTagRequestTest.php b/tests/Integration/Requests/SongTagRequestTest.php index 6d15b368..bfe139fe 100644 --- a/tests/Integration/Requests/SongTagRequestTest.php +++ b/tests/Integration/Requests/SongTagRequestTest.php @@ -27,7 +27,6 @@ protected function setUp(): void $this->anyTagName = IntegrationTestData::getResult("get_song_tags", "any_tag.name"); $this->anotherTagId = IntegrationTestData::getResultAsInt("get_song_tags", "another_tag.id"); $this->anotherTagName = IntegrationTestData::getResult("get_song_tags", "another_tag.name"); - CTLog::enableHttpLog(); } public function testSongTagAll() diff --git a/tests/Integration/TestCaseAuthenticated.php b/tests/Integration/TestCaseAuthenticated.php index 56059476..50b6de06 100644 --- a/tests/Integration/TestCaseAuthenticated.php +++ b/tests/Integration/TestCaseAuthenticated.php @@ -3,6 +3,8 @@ namespace CTApi\Test\Integration; use CTApi\CTConfig; +use CTApi\Exceptions\CTRequestException; +use CTApi\Models\Groups\Person\PersonRequest; use PHPUnit\Framework\TestCase; class TestCaseAuthenticated extends TestCase @@ -13,6 +15,14 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); + if(self::$configIsInitialized){ + try{ + PersonRequest::whoami(); + }catch(CTRequestException $exception){ + self::reauthenticateChurchToolsUser(); + } + } + if (self::$configIsInitialized == false || self::cookieJarIsEmpty()) { self::reauthenticateChurchToolsUser(); } diff --git a/tests/Integration/integration-test-data.json b/tests/Integration/integration-test-data.json index 11a36f03..d85c054b 100644 --- a/tests/Integration/integration-test-data.json +++ b/tests/Integration/integration-test-data.json @@ -179,7 +179,7 @@ "end_date": "2023-06-01" }, "result": { - "number_of_elements": 1, + "number_of_elements": 2, "first_element": { "id": 1, "name": "Gottesdienst" @@ -277,7 +277,7 @@ }, "result": { "comment": "Ski-Urlaub", - "reason": "Urlaub", + "reason": "absent.reason.vacation", "start_date": "2023-01-02", "end_date": "2023-01-05" } @@ -466,7 +466,7 @@ "id": 4 }, "fieldType": { - "name": "Textfeld", + "name": "fieldtype.text", "internCode": "text", "id": 1 }, From 775638afae65bc3949ee22a8260f5f28fca4c8eb Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 11 Dec 2023 12:22:26 +0100 Subject: [PATCH 7/8] chore(github): update ci --- .github/workflows/integration-tests.yml | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 2d86f502..6a9ffa2e 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -41,12 +41,32 @@ jobs: - name: Create integration-config file run: | - printf "$INTEGRATION_CONFIG" >> tests/Integration/integration.ini - printf "$INTEGRATION_CONFIG" - cat tests/Integration/integration.ini + printf '%s\n' "$INTEGRATION_CONFIG" > tests/Integration/integration.ini shell: bash env: INTEGRATION_CONFIG: ${{ secrets.INTEGRATION_CONFIG }} + - name: Check if integration-config file exists + run: | + ls + if [ -f "tests/Integration/integration.ini" ] + then + echo "Integration file exists" + else + echo "Error: Could not find integration config file" + throw "Error: Could not find integration config file" + fi + + - name: Check if integration file is empty + run: | + ls + if [ -s "tests/Integration/integration.ini" ] + then + echo "Integration config file is not empty" + else + echo "Error: Integration config file is empty" + throw "Error: Integration config file is empty" + fi + - name: Run integration test suite run: composer run-script test-integration \ No newline at end of file From 8cecd3733654482705c164f8689d7fd8f0eace47 Mon Sep 17 00:00:00 2001 From: DumbergerL Date: Mon, 11 Dec 2023 12:36:58 +0100 Subject: [PATCH 8/8] chore(github): check if config exists --- .github/workflows/integration-tests.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 6a9ffa2e..ee4ad3d2 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -41,14 +41,13 @@ jobs: - name: Create integration-config file run: | - printf '%s\n' "$INTEGRATION_CONFIG" > tests/Integration/integration.ini + printf '%s' "$INTEGRATION_CONFIG" > tests/Integration/integration.ini shell: bash env: INTEGRATION_CONFIG: ${{ secrets.INTEGRATION_CONFIG }} - name: Check if integration-config file exists run: | - ls if [ -f "tests/Integration/integration.ini" ] then echo "Integration file exists" @@ -56,10 +55,13 @@ jobs: echo "Error: Could not find integration config file" throw "Error: Could not find integration config file" fi + echo "FILE SIZES IN tests/Integration:\n" + cd tests + cd Integration + ls -lh - name: Check if integration file is empty run: | - ls if [ -s "tests/Integration/integration.ini" ] then echo "Integration config file is not empty"