Skip to content
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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TEST_APPSIGNAL_KEY=
TEST_LOGOWL_KEY=
TEST_RAYGUN_KEY=
TEST_SENTRY_DSN=
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ notifications:
before_script: composer install --ignore-platform-reqs

script:
- vendor/bin/phpunit --configuration phpunit.xml
- vendor/bin/psalm --show-info=true
- composer check
- composer test
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,20 @@ Below is a list of supported adapters, and thier compatibly tested versions alon

## Tests

To run all unit tests, use the following Docker command:
If you need to install dependencies, run:

```bash
docker run --rm -e TEST_RAYGUN_KEY=KKKK -e TEST_APPSIGNAL_KEY=XXXX -e TEST_SENTRY_DSN=XXXX -v $(pwd):$(pwd):rw -w $(pwd) php:8.0-cli-alpine sh -c "vendor/bin/phpunit --configuration phpunit.xml tests"
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist
```

To run all unit tests, prepare the `.env` file using `.env.example` as a template. Then, run:

```bash
docker run --rm --interactive --tty --env-file .env \
--volume $PWD:/app \
composer test
```

> Make sure to replace `TEST_SENTRY_DSN` with actual keys from Sentry.
Expand All @@ -105,7 +115,9 @@ docker run --rm -e TEST_RAYGUN_KEY=KKKK -e TEST_APPSIGNAL_KEY=XXXX -e TEST_SENTR
To run static code analysis, use the following Psalm command:

```bash
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) php:8.0-cli-alpine sh -c "vendor/bin/psalm --show-info=true"
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer check
```

## System Requirements
Expand Down
14 changes: 13 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@
"scripts": {
"check": "./vendor/bin/phpstan analyse --level max src tests",
"lint": "./vendor/bin/pint --test",
"format": "./vendor/bin/pint"
"format": "./vendor/bin/pint",
"test-unit": "./vendor/bin/phpunit --configuration phpunit.xml --testsuite unit --debug",
"test-e2e": "./vendor/bin/phpunit --configuration phpunit.xml --testsuite e2e --debug",
"test": [
"@test-unit",
"@test-e2e"
]
},
"autoload": {
"psr-4": {"Utopia\\Logger\\": "src/Logger"}
},
"autoload-dev": {
"psr-4": {
"Utopia\\Tests\\E2E\\":"tests/e2e",
"Utopia\\Tests\\Unit\\":"tests/unit"
}
},
"require": {
"php": ">=8.0"
},
Expand Down
31 changes: 25 additions & 6 deletions docs/tutorials/add-logger-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,35 @@ In `src/Logger/Logger.php` update variable `const PROVIDERS` to include your pro

## 3. Test your adapter

After you finished adding your new adapter, you should write a proper test for it. To do that, you enter `tests/LoggerTests.php` and take a look at `testAdapters()` method. In there, we already build a whole log object and all you need to do is to push the log using your provider. Take a look at how test for already existign adapter looks or use template below:
After you finished adding your new adapter, you should write a proper test for it. To do that, you enter `tests/e2e/Adapter` and create a new `XXXTest.php` wtih something like:

```php
// Test [ADAPTER_NAME]
$adapter = new [ADAPTER_NAME](); // TODO: Use `getenv()` method to provide private keys as env variables
$logger = new Logger($adapter);
$response = $logger->addLog($log);
// TODO: Expect success response either by checking body or response status code using `assertEquals()`
<?php

namespace Utopia\Tests\E2E\Adapter;

use Utopia\Logger\Adapter\[XXX];
use Utopia\Tests\E2E\AdapterBase;

class [XXX]Test extends AdapterBase
{
protected function setUp(): void
{
parent::setUp();
$param1 = \getenv('TEST_XXX_PARAM_1');
$param2 = \getenv('TEST_XXX_PARAM_2');
$this->adapter = new [XXX](
$param1 ? $param1 : '',
$param2 ? $param2 : '',
);
$this->expected = 202; // Expected status code for successful log creation
}
}

```

Take a look at any other adapter as an example.

## 4. Raise a pull request

First of all, commit the changes with the message `Added XXX Adapter` (where `XXX` is adapter name) and push it. This will publish a new branch to your forked version of utopia/logger. If you visit it at `github.com/YOUR_USERNAME/logger`, you will see a new alert saying you are ready to submit a pull request. Follow the steps GitHub provides, and at the end, you will have your pull request submitted.
Expand Down
7 changes: 5 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
stopOnFailure="false"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="e2e">
<directory>./tests/e2e</directory>
</testsuite>
</testsuites>
</phpunit>
185 changes: 0 additions & 185 deletions tests/LoggerTest.php

This file was deleted.

16 changes: 16 additions & 0 deletions tests/e2e/Adapter/AppSignalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Utopia\Tests\E2E\Adapter;

use Utopia\Logger\Adapter\AppSignal;
use Utopia\Tests\E2E\AdapterBase;

class AppSignalTest extends AdapterBase
{
protected function setUp(): void
{
parent::setUp();
$appSignalKey = \getenv('TEST_APPSIGNAL_KEY');
$this->adapter = new AppSignal($appSignalKey ? $appSignalKey : '');
}
}
16 changes: 16 additions & 0 deletions tests/e2e/Adapter/LogOwlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Utopia\Tests\E2E\Adapter;

use Utopia\Logger\Adapter\LogOwl;
use Utopia\Tests\E2E\AdapterBase;

class LogOwlTest extends AdapterBase
{
protected function setUp(): void
{
parent::setUp();
$logOwlKey = \getenv('TEST_LOGOWL_KEY');
$this->adapter = new LogOwl($logOwlKey ? $logOwlKey : '');
}
}
17 changes: 17 additions & 0 deletions tests/e2e/Adapter/RaygunTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Utopia\Tests\E2E\Adapter;

use Utopia\Logger\Adapter\Raygun;
use Utopia\Tests\E2E\AdapterBase;

class RaygunTest extends AdapterBase
{
protected function setUp(): void
{
parent::setUp();
$raygunKey = \getenv('TEST_RAYGUN_KEY');
$this->adapter = new Raygun($raygunKey ? $raygunKey : '');
$this->expected = 202;
}
}
15 changes: 15 additions & 0 deletions tests/e2e/Adapter/SentryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Utopia\Tests\E2E\Adapter;

use Utopia\Logger\Adapter\Sentry;
use Utopia\Tests\E2E\AdapterBase;

class SentryTest extends AdapterBase
{
protected function setUp(): void
{
parent::setUp();
$this->adapter = new Sentry(\getenv('TEST_SENTRY_DSN') ?: '');
}
}
Loading