2023-07-10 09:20:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Tests;
|
|
|
|
|
2023-07-10 07:47:28 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2023-07-10 09:20:36 +00:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2023-07-10 07:47:28 +00:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
use App\CommandShow;
|
|
|
|
|
2023-07-10 09:20:36 +00:00
|
|
|
#[CoversClass(CommandShow::class)]
|
|
|
|
final class CommandShowTest extends \PHPUnit\Framework\TestCase
|
2023-07-10 07:47:28 +00:00
|
|
|
{
|
2023-07-10 09:20:36 +00:00
|
|
|
public function testInvalidConfig(): void
|
2023-07-10 07:47:28 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
$applicationd = new Application('backup', "1.1.1");
|
|
|
|
|
|
|
|
$applicationd->add(new CommandShow());
|
|
|
|
|
|
|
|
|
|
|
|
$command = $applicationd->find('show');
|
|
|
|
$commandTester = new CommandTester($command);
|
2023-07-10 09:20:36 +00:00
|
|
|
$commandTester->execute(['config' => "bad_file"]);
|
2023-07-10 07:47:28 +00:00
|
|
|
|
|
|
|
$output = $commandTester->getDisplay();
|
|
|
|
$this->assertStringContainsString('[ERROR] Configuration error: File "bad_file" does not exist.', $output);
|
|
|
|
}
|
|
|
|
|
2023-07-10 09:20:36 +00:00
|
|
|
public function testGoodConfig(): void
|
2023-07-10 07:47:28 +00:00
|
|
|
{
|
|
|
|
exec('rclone test makefiles temp/source 2>&1');
|
2023-07-10 09:20:36 +00:00
|
|
|
|
2023-07-10 07:47:28 +00:00
|
|
|
$applicationd = new Application('backup', "1.1.1");
|
|
|
|
|
|
|
|
$applicationd->add(new CommandShow());
|
|
|
|
|
|
|
|
|
|
|
|
$command = $applicationd->find('show');
|
|
|
|
$commandTester = new CommandTester($command);
|
2023-07-10 09:20:36 +00:00
|
|
|
$commandTester->execute(['config' => "config.example.yml"]);
|
2023-07-10 07:47:28 +00:00
|
|
|
|
|
|
|
$output = $commandTester->getDisplay();
|
|
|
|
$this->assertStringContainsString('Example', $output);
|
|
|
|
$this->assertStringContainsString('temp/source', $output);
|
|
|
|
$this->assertStringContainsString('temp/destination', $output);
|
|
|
|
}
|
2023-07-10 09:20:36 +00:00
|
|
|
}
|