More unittests

This commit is contained in:
2023-11-14 09:09:15 +00:00
parent bedc666f7c
commit cadb207758
7 changed files with 136 additions and 54 deletions

View File

@ -6,6 +6,7 @@ namespace App\Tests;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Log\LoggerInterface;
use App\App;
@ -25,4 +26,55 @@ final class AppTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('output.log', $app->getConfig('log'));
$this->assertInstanceOf(LoggerInterface::class, $app->getLogger());
}
public function testBadConfigFileSyntaxError(): void
{
$this->expectException(\TypeError::class);
$app = new App('tests/config/bad/syntaxerror.yml');
$app->getConfig('rclone');
$app->getConfig('rclone.path');
$app->getConfig('backup');
$app->getConfig('notification');
$app->getConfig('log');
$app->getConfig('templates');
$app->getConfig('templates.notify');
$app->getConfig('templates.error');
$this->fail('Exception was not thrown');
}
public function testBadConfigFileEmpty(): void
{
$this->expectException(\TypeError::class);
$app = new App('tests/config/bad/empty.yml');
$app->getConfig('rclone');
$app->getConfig('rclone.path');
$app->getConfig('backup');
$app->getConfig('notification');
$app->getConfig('log');
$app->getConfig('templates');
$app->getConfig('templates.notify');
$app->getConfig('templates.error');
$this->fail('Exception was not thrown');
}
public function testBadConfigFileTypos(): void
{
$this->expectException(\League\Config\Exception\ValidationException::class);
$app = new App('tests/config/bad/typos.yml');
$app->getConfig('rclone');
$app->getConfig('rclone.path');
$app->getConfig('backup');
$app->getConfig('notification');
$app->getConfig('log');
$app->getConfig('templates');
$app->getConfig('templates.notify');
$app->getConfig('templates.error');
$this->fail('Exception was not thrown');
}
}

View File

View File

@ -0,0 +1,6 @@
<note>
<to>Someone</to>
<from>Me</from>
<heading>Title</heading>
<body>Text</body>
</note>

View File

@ -0,0 +1,26 @@
notifikation:
- type: Ntfy
domain: https://ntfy.jcktrue.dk
topic: testing
logger: output.log
rclone:
option:
bwlimit: 6M
backup:
- titel: Example
src: temp/source
dest: temp/destination
template:
notification: |
{{ config.title }}
From {{ config.source }} to {{ config.destination }}
Backup started: {{ start | date }}
Source size: {{ source_size | formatBytes}}
Destination before: {{ destination_size_before | formatBytes}}
Destination after: {{ destination_size_after | formatBytes}}
Destination change : {{ (destination_size_after - destination_size_before) | formatBytes}}
Backup completed: {{ end | date }}
warn: |
{{ config.title }}
Error {{ config.source }} to {{ config.destination }}
{{ exception }}