Jens True
bedc666f7c
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
111 lines
3.2 KiB
PHP
111 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use Symfony\Component\Console\Application;
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
use App\CommandBackup;
|
|
|
|
#[CoversClass(CommandBackup::class)]
|
|
final class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
if (!is_dir('temp')) {
|
|
mkdir('temp');
|
|
}
|
|
if (!is_dir('temp/destination')) {
|
|
mkdir('temp/destination');
|
|
}
|
|
exec('rclone test makefiles --files 10 temp/source 2>&1');
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
exec('rclone purge temp 2>&1');
|
|
|
|
if (is_dir('temp/destination')) {
|
|
rmdir('temp/destination');
|
|
}
|
|
|
|
if (is_dir("temp")) {
|
|
rmdir('temp');
|
|
}
|
|
}
|
|
|
|
public function testBadConfig(): void
|
|
{
|
|
$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 testNoCommand(): void
|
|
{
|
|
$applicationd = new Application('backup', "1.1.1");
|
|
|
|
$applicationd->add(new CommandBackup());
|
|
|
|
$command = $applicationd->find('backup');
|
|
$commandTester = new CommandTester($command);
|
|
$this->expectException(\Exception::class);
|
|
$commandTester->execute([]);
|
|
$this->fail('Exception was not thrown');
|
|
}
|
|
|
|
public function testGoodConfig(): void
|
|
{
|
|
$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(): void
|
|
{
|
|
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(): void
|
|
{
|
|
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);
|
|
}
|
|
}
|