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 integration tests #144

Merged
merged 4 commits into from
May 9, 2023
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- Authenticate CTClient with session cookie instead of api-key ([PR142](https://github.com/5pm-HDH/churchtools-api/pull/142))
- GH-Action for integration-tests ([PR143](https://github.com/5pm-HDH/churchtools-api/pull/143))
- GH-Action for integration-tests ([PR143](https://github.com/5pm-HDH/churchtools-api/pull/143), [PR144](https://github.com/5pm-HDH/churchtools-api/pull/144))

### Fixed

Expand Down
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# ChurchTools-API Client

![example workflow](https://github.com/5pm-HDH/churchtools-api/actions/workflows/unit-tests.yml/badge.svg)
![static-code-analysis workflow](https://github.com/5pm-HDH/churchtools-api/actions/workflows/static-code-analysis.yml/badge.svg)

![example workflow](https://github.com/5pm-HDH/churchtools-api/actions/workflows/static-code-analysis.yml/badge.svg)
![unit-test workflow](https://github.com/5pm-HDH/churchtools-api/actions/workflows/unit-tests.yml/badge.svg)

ChurchTools-API Client is a php based wrapper of the ChurchTools api. This api is tested with the ChurchTools
version <version>3.97.1</version>
![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.97.1</version>.

## Installation

Go to the project-root and install ChurchTools-api via [composer](https://getcomposer.org/):
Go to the project-root and install ChurchTools-API via [composer](https://getcomposer.org/):

```
composer require 5pm-hdh/churchtools-api
```

Load all the dependency-packages into the PHP-Project with the command:
Load all dependency packages into the PHP project using the following code:

```php
<?php
Expand Down Expand Up @@ -43,11 +45,11 @@ CTConfig::authWithCredentials(
```

For more information visit the [CTConfig documentation](/docs/out/CTConfig.md)
From now on all features of the ChurchTools-api are available.
From now on all features of the ChurchTools-API are available.

### Requests and Models

The whole ChurchTools-api client is build on top of the Requests and Models. [Requests](/docs/out/Requests.md) provide
The whole ChurchTools-API client is build on top of the Requests and Models. [Requests](/docs/out/Requests.md) provide
an interface to specify your api call by adding filtering, pagination and sorting. [Models](/docs/out/Models.md)
represent the data, that the Requests retrieve. More informations can be found in the documentation.

Expand All @@ -67,8 +69,8 @@ All APIs with examples:
* [File-API](/docs/out/FileAPI.md)
* [Search-API](/docs/out/SearchAPI.md)

The following short examples show the power of this ChurchTools-api client and gives a rough overview over the
possibilities:
The following brief examples demonstrate the capabilities of the ChurchTools-API client and provide a general overview
of its potential uses:

#### Example: Person-API

Expand Down Expand Up @@ -189,7 +191,7 @@ Result:

## Support / Contribute

Please feel free to Support or Contribute this project.
We welcome your support and contributions to this project.

### CTLog - Logging Request

Expand All @@ -203,8 +205,8 @@ CTLog::enableFileLog( false ); //disable logfile
CTLog::enableFileLog(); // enable logfile
```

By default, all Error, Critical, Alert and Emergency logs will be displayed in the console. If you want to show further
log-levels on the console you can use the CTConfig-Debug Option or set it direct in the CTLog facade:
By default, the console will display all logs of Error, Critical, Alert, and Emergency levels. If you wish to display
additional log levels on the console, you may use the CTConfig-Debug option or set it directly in the CTLog facade:

```php
CTConfig::enableDebug();
Expand All @@ -230,10 +232,18 @@ Further information on [CTLog-Page](/docs/out/CTLog.md):

The API-Wrapper provides custom exceptions. More on this page: [Error-Handling](/docs/out/ErrorHandling.md)

### Unit- and Integration-Tests

To access the unit tests, navigate to the "tests/unit" directory. You may use the standard PHPUnit\Framework\TestCase to
test small sections of code, or use TestCaseHttpMocked to simulate an HTTP request.

For integration tests, requests are sent directly to a ChurchTools instance. The "integration-test-data.json" file
contains all available test data scenarios. All integration tests are automatically executed via Github Actions.

### Doc-Generator

The Doc-Generator processes all Doc-Files and executes the PHP-Code examples to ensure that they are valid. More on this
page: [Doc-Generator](/docs/Docs.md)
The Doc-Generator parses all documentation files and runs the PHP code examples to verify their validity. For additional
information, please refer to this page: [Doc-Generator](/docs/Docs.md)

## License

Expand Down
42 changes: 27 additions & 15 deletions docs/Docs.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
# Documentation

The documentation in the `docs/out`-Directory is generated by the DocGenerator-Script. The DocGenerator can be executed with this composer command:
The documentation in the docs/out directory is generated by running the DocGenerator script. To execute the
DocGenerator, run the following composer command:

```
composer run-script docs-generator
```

If you change something in the Docs (`docs/src/ressources`) make sure you execute the DocGenerator and commit also the generated output files!
If you make changes to the docs (docs/src/resources), be sure to run the DocGenerator and commit the generated output
files.

The Generator will take the template-docs (docs/src/ressources) and transform the code samples to real code for the
documentation. There are two types of code samples:

The Generator will take the template-docs (`docs/src/ressources`) and transform the code samples to real code for the documentation. There are two types of code samples:
1. Templates to include Unit-Test (see [Template-Snippets](#template-snippets))
2. Code examples that are executed (see [PHP-Snippets](#php-snippets-deprecated))

## Template-Snippets

With the template-snippets code from unit-tests can be included. The main adventage is, that this code also extends and improves the unit-test suite. The Github CI executes this unit-tests and ensure that they are working code. To include a unit-test code-sample you cann use this template syntax:
With the template-snippets, code from unit-tests can be included. This has the main advantage that this code also
extends and improves the unit-test suite. The Github CI executes these unit-tests and ensures that they are working
code. To include a unit-test code-sample, use this template syntax:

```
{{ \Tests\Unit\Docs\EventRequestTest.testEventRequestDocExample }}
```

The Doc-Generator takes the unit-test code an transform the `assertEquals`-Statements to a more readable code. All Unit-Test for the documentation are stored in the directory `tests/unit/docs/`. For example the already mentioned unit-test `testEventRequestDocExample` has this assert-statement:
The Doc-Generator takes the unit-test code and transforms the assertEquals statements to more readable code. All
Unit-Test for the documentation are stored in the directory tests/unit/docs/. For example, the already mentioned
unit-test testEventRequestDocExample has this assert-statement:

```php
$this->assertEquals(21, $christmasService->getId());
Expand All @@ -33,15 +41,17 @@ var_dump( $christmasService->getId());
// Output: 21
```

- ⚠ Just use `assertEquals`-Statements. Other Assertions wont be transformed.
- ⚠ Don't use Assert-Statements in a loop or if-/switch-statement.
- ⚠ Only use simple values as assert-paremter (string, int, boolean) and not objects or arrays.
- ⚠ Only use `assertEquals` statements as other assertions won't be transformed.
- ⚠ Do not use assert statements inside a loop or if/switch statement.
- ⚠ Only use simple values like string, integer, and boolean as assert parameters, not objects or arrays.

## PHP-Snippets (Deprecated)

⚠ Don't use this approach for new documentation. The drawback of this technique is that all code-samples are not extending the unit-test suite and therefore are not tested by the Unit-Test CI-Pipeline.
⚠ It is not recommended to use PHP-Snippets for new documentation because they are not included in the unit-test suite
and are therefore not tested by the CI-Pipeline.

PHP-Snippets are used by `docs/src/ressources/CTConfig.md`. The idea is quite simple. All code examples are executed by the doc-generator. With the `dd`-function the content of variables can be displayed to the user.
PHP-Snippets are used in docs/src/ressources/CTConfig.md. The code examples are executed by the doc-generator and the
content of variables can be displayed to the user using the dd function.

This example Code-Snippet...

Expand All @@ -58,13 +68,15 @@ echo ($a);
// OUTPUT: 4
```

The Generator converts the "dd"-Function call to an "echo" call. In the next Line it will display the content of the variable $a.

- ⚠ The `dd(...)`-Method is not allowed in any kind of Loop or If/Switch-Statement.
The Doc-Generator replaces the "dd" function call with an "echo" call to display the content of a variable. ⚠ However,
it is not permitted to use the dd(...) method in any kind of loop or if/switch-statement.

## Execution Enviroment
The Generator-Script builds the CTClientMock-Enviroment. All Http calls are redirected to the Json-Files in the `tests/unit/HttpMock/data`-directory.

The Generator-Script creates the CTClientMock environment which redirects all HTTP calls to the JSON files located in
the tests/unit/HttpMock/data directory.

## Github-Action

The doc-generator GithubAction executes the DocGenerator. Then it checks if there are any uncommited changes. If so it fails. To fix this execute the doc-generator locally an commit all generated doc files.
The GitHub Action for the doc-generator runs the DocGenerator and checks for any uncommitted changes. If there are any,
the Action will fail. To resolve this, run the DocGenerator locally and commit all the generated doc files.
7 changes: 5 additions & 2 deletions tests/integration/Requests/EventRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public function testGetAllEvents(): void
{
$allEvents = EventRequest::all();

$this->assertFalse(empty(sizeof($allEvents)));
$this->assertInstanceOf(Event::class, $allEvents[0]);
if (sizeof($allEvents) > 0) {
$this->assertInstanceOf(Event::class, $allEvents[0]);
} else {
$this->assertTrue(true);
}
}

public function testGetWhereEvents(): void
Expand Down
11 changes: 7 additions & 4 deletions tests/integration/Requests/PersonRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Integration\Requests;

use CTApi\CTConfig;
use CTApi\Exceptions\CTRequestException;
use CTApi\Models\Event;
use CTApi\Models\Group;
Expand Down Expand Up @@ -82,9 +81,13 @@ public function testRequestEvents(): void
$requestEventBuilder = $person->requestEvents();
$this->assertNotNull($requestEventBuilder);
$events = $requestEventBuilder->get();
$this->assertTrue(sizeof($events) > 0);
foreach ($events as $event) {
$this->assertInstanceOf(Event::class, $event);

if (sizeof($events) > 0) {
foreach ($events as $event) {
$this->assertInstanceOf(Event::class, $event);
}
} else {
$this->assertTrue(true);
}
}

Expand Down