Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testsuites dumbergerl #185

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,34 @@ jobs:

- name: Create integration-config file
run: |
printf "$INTEGRATION_CONFIG" >> tests/integration/integration.ini
printf "$INTEGRATION_CONFIG"
cat 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: |
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
echo "FILE SIZES IN tests/Integration:\n"
cd tests
cd Integration
ls -lh

- name: Check if integration file is empty
run: |
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version>3.102.0</version>.
version <version>3.104.0</version>.

> [!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).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
verbose="true">
<testsuites>
<testsuite name="unit">
<directory>tests/unit</directory>
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/integration</directory>
<directory>tests/Integration</directory>
</testsuite>
</testsuites>

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Common/Auth/AuthRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 24 additions & 0 deletions src/Models/Common/DBField/DBField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Models/Common/DBField/DBFieldForKeysRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function get(): array
private function findDBField(string $dbFieldKey): ?DBField
{
foreach ($this->allDBFields as $dbField) {
if ($dbField->getColumn() == $dbFieldKey) {
if ($dbField->getKey() == $dbFieldKey) {
return $dbField;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Request/OrderByCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/Models/download-folder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
16 changes: 15 additions & 1 deletion tests/Integration/Requests/DBFieldRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
25 changes: 18 additions & 7 deletions tests/Integration/Requests/GroupHierarchieRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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);
Expand All @@ -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());
}
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/Requests/SongTagRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/TestCaseAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/integration-test-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
"end_date": "2023-06-01"
},
"result": {
"number_of_elements": 1,
"number_of_elements": 2,
"first_element": {
"id": 1,
"name": "Gottesdienst"
Expand Down Expand Up @@ -277,7 +277,7 @@
},
"result": {
"comment": "Ski-Urlaub",
"reason": "Urlaub",
"reason": "absent.reason.vacation",
"start_date": "2023-01-02",
"end_date": "2023-01-05"
}
Expand Down Expand Up @@ -466,7 +466,7 @@
"id": 4
},
"fieldType": {
"name": "Textfeld",
"name": "fieldtype.text",
"internCode": "text",
"id": 1
},
Expand Down
1 change: 0 additions & 1 deletion tests/integration/Models/download-folder/.gitignore

This file was deleted.

Loading