backupscript/tests/Rclone/RcloneTest.php

71 lines
1.9 KiB
PHP
Raw Normal View History

2023-07-10 09:20:36 +00:00
<?php
declare(strict_types=1);
namespace App\Tests;
2023-06-15 10:15:44 +00:00
2023-06-15 14:10:17 +00:00
use App\Rclone\Rclone;
2023-05-31 09:42:39 +00:00
use PHPUnit\Framework\TestCase;
final class RcloneTest extends TestCase
{
2023-06-15 10:15:44 +00:00
protected function setUp(): void
{
2023-07-10 07:47:28 +00:00
exec('rclone test makefiles temp/source 2>&1');
2023-06-15 10:15:44 +00:00
}
protected function tearDown(): void
{
2023-07-10 09:20:36 +00:00
exec('rclone purge temp 2>&1');
2023-06-15 10:15:44 +00:00
}
2023-05-31 10:12:52 +00:00
public function testRclonePath(): void
2023-05-31 09:42:39 +00:00
{
$this->expectException(\Exception::class);
2023-06-15 14:10:17 +00:00
$rclone = new Rclone('invalid');
2023-07-10 09:20:36 +00:00
$this->assertEquals('', $rclone->getVersion());
2023-05-31 09:42:39 +00:00
}
2023-05-31 10:12:52 +00:00
public function testRcloneInvalidVersion(): void
{
$this->expectException(\Exception::class);
2023-06-15 14:10:17 +00:00
$rclone = new Rclone('uname');
2023-07-10 09:20:36 +00:00
$this->assertEquals('', $rclone->getVersion());
2023-05-31 10:12:52 +00:00
}
2023-05-31 09:42:39 +00:00
2023-05-31 10:12:52 +00:00
public function testRcloneValidVersion(): void
2023-05-31 09:42:39 +00:00
{
2023-06-15 14:10:17 +00:00
$rclone = new Rclone();
2023-07-10 09:20:36 +00:00
$this->assertStringStartsWith('rclone', $rclone->getVersion());
2023-05-31 09:42:39 +00:00
}
2023-06-15 10:15:44 +00:00
public function testRcloneSize(): void
{
2023-06-15 14:10:17 +00:00
$rclone = new Rclone();
2023-06-15 10:15:44 +00:00
$size = $rclone->getSize('temp/source');
$this->assertGreaterThan(10000, $size);
$this->expectException(\Exception::class);
$this->expectExceptionMessage("ERROR");
$size = $rclone->getSize('temp/bogus-source');
$this->assertEquals(0, $size);
}
public function testRcloneCopy(): void
{
2023-06-15 14:10:17 +00:00
$rclone = new Rclone();
2023-07-10 09:20:36 +00:00
$rclone->copy('temp/source', 'temp/destination');
2023-06-15 10:15:44 +00:00
$this->assertDirectoryExists('temp/destination');
2023-06-15 14:10:17 +00:00
$rclone = new Rclone();
2023-07-10 09:20:36 +00:00
$rclone->copy('temp/source', 'temp/destination', ['bwlimit' => '6M']);
2023-06-15 10:15:44 +00:00
$this->assertDirectoryExists('temp/destination');
2023-07-10 09:20:36 +00:00
2023-06-15 10:15:44 +00:00
$this->expectException(\Exception::class);
$this->expectExceptionMessage("ERROR");
2023-07-10 09:20:36 +00:00
$rclone->copy('temp/bogus-source', 'temp/bogus-destination');
2023-06-15 10:15:44 +00:00
$this->assertDirectoryDoesNotExist('temp/bogus-destination');
}
2023-07-10 09:20:36 +00:00
}