This commit is contained in:
2
Makefile
2
Makefile
@ -21,5 +21,5 @@ install-dev:
|
|||||||
test:
|
test:
|
||||||
vendor/bin/phpunit tests
|
vendor/bin/phpunit tests
|
||||||
test-coverage:
|
test-coverage:
|
||||||
vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html
|
vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --branch-coverage --testdox-html output/test.html
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
notification:
|
notification:
|
||||||
- type: Ntfy
|
- type: Ntfy
|
||||||
domain: https://ntfy.jcktrue.dk
|
domain: https://ntfy.jcktrue.dk
|
||||||
topic: backup
|
topic: testing
|
||||||
log: output.log
|
log: output.log
|
||||||
rclone:
|
rclone:
|
||||||
options:
|
options:
|
||||||
|
@ -75,6 +75,7 @@ class CommandBackup extends Command
|
|||||||
$message = $render->render('notify', $template);
|
$message = $render->render('notify', $template);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$message = $e->getMessage();
|
$message = $e->getMessage();
|
||||||
|
$sio->error($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification->send($title, $message);
|
$notification->send($title, $message);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
@ -6,7 +7,36 @@ use App\CommandBackup;
|
|||||||
|
|
||||||
class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
public function testInvalidConfig()
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
mkdir('temp');
|
||||||
|
mkdir('temp/destination');
|
||||||
|
exec('rclone test makefiles temp/source 2>&1');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
exec('rclone purge temp 2>&1', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testBadConfig()
|
||||||
|
{
|
||||||
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
|
$applicationd->add(new CommandBackup());
|
||||||
|
|
||||||
|
|
||||||
|
$command = $applicationd->find('backup');
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
$commandTester->execute(['config'=>"bad_file"]);
|
||||||
|
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertStringContainsString('[ERROR] Configuration error:File "bad_file" does not exist.', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGoodConfig()
|
||||||
{
|
{
|
||||||
|
|
||||||
$applicationd = new Application('backup', "1.1.1");
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
@ -16,9 +46,41 @@ class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$command = $applicationd->find('backup');
|
$command = $applicationd->find('backup');
|
||||||
$commandTester = new CommandTester($command);
|
$commandTester = new CommandTester($command);
|
||||||
$commandTester->execute(['config'=>"empty"]);
|
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||||
|
|
||||||
$output = $commandTester->getDisplay();
|
$output = $commandTester->getDisplay();
|
||||||
$this->assertStringContainsString('backup', $output);
|
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoDestinationFolder()
|
||||||
|
{
|
||||||
|
exec('rclone purge temp/destination 2>&1', $output);
|
||||||
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
|
$applicationd->add(new CommandBackup());
|
||||||
|
|
||||||
|
|
||||||
|
$command = $applicationd->find('backup');
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||||
|
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoSourceFolder()
|
||||||
|
{
|
||||||
|
exec('rclone purge temp/source 2>&1', $output);
|
||||||
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
|
$applicationd->add(new CommandBackup());
|
||||||
|
|
||||||
|
|
||||||
|
$command = $applicationd->find('backup');
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||||
|
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertStringContainsString('[OK] Complete ', $output);
|
||||||
}
|
}
|
||||||
}
|
}
|
45
tests/CommandShowTest.php
Normal file
45
tests/CommandShowTest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
use App\CommandShow;
|
||||||
|
|
||||||
|
class CommandShowTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
public function testInvalidConfig()
|
||||||
|
{
|
||||||
|
|
||||||
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
|
$applicationd->add(new CommandShow());
|
||||||
|
|
||||||
|
|
||||||
|
$command = $applicationd->find('show');
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
$commandTester->execute(['config'=>"bad_file"]);
|
||||||
|
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertStringContainsString('[ERROR] Configuration error: File "bad_file" does not exist.', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGoodConfig()
|
||||||
|
{
|
||||||
|
exec('rclone test makefiles temp/source 2>&1');
|
||||||
|
|
||||||
|
$applicationd = new Application('backup', "1.1.1");
|
||||||
|
|
||||||
|
$applicationd->add(new CommandShow());
|
||||||
|
|
||||||
|
|
||||||
|
$command = $applicationd->find('show');
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
$commandTester->execute(['config'=>"config.example.yml"]);
|
||||||
|
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertStringContainsString('Example', $output);
|
||||||
|
$this->assertStringContainsString('temp/source', $output);
|
||||||
|
$this->assertStringContainsString('temp/destination', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -7,7 +7,10 @@ final class RcloneTest extends TestCase
|
|||||||
{
|
{
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
shell_exec('rclone test makefiles temp/source 2>&1');
|
if(!is_dir('temp')) {
|
||||||
|
mkdir('temp');
|
||||||
|
}
|
||||||
|
exec('rclone test makefiles temp/source 2>&1');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
|
Reference in New Issue
Block a user