backupscript/tests/CommandBackupTest.php
Jens True 534c8cdbe6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
More testing.
2023-07-10 07:47:28 +00:00

86 lines
2.4 KiB
PHP

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use App\CommandBackup;
class CommandBackupTest extends \PHPUnit\Framework\TestCase
{
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->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 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);
}
}