This commit is contained in:
		
							
								
								
									
										29
									
								
								tests/CommandBackupTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/CommandBackupTest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
<?php 
 | 
			
		||||
namespace App\Tests;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Symfony\Component\Console\Application;
 | 
			
		||||
use Symfony\Component\Console\Tester\CommandTester;
 | 
			
		||||
use App\CommandBackup;
 | 
			
		||||
 | 
			
		||||
class CommandBackupTest extends \PHPUnit\Framework\TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testExecute()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        $applicationd = new Application('backup', "1.1.1");
 | 
			
		||||
 | 
			
		||||
        $applicationd->add(new CommandBackup());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $command = $applicationd->find('backup');
 | 
			
		||||
        $commandTester = new CommandTester($command);
 | 
			
		||||
        $commandTester->execute([]);
 | 
			
		||||
 | 
			
		||||
        $commandTester->assertCommandIsSuccessful();
 | 
			
		||||
 | 
			
		||||
        // the output of the command in the console
 | 
			
		||||
        $output = $commandTester->getDisplay();
 | 
			
		||||
        $this->assertStringContainsString('backup', $output);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,23 +1,65 @@
 | 
			
		||||
<?php declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
 | 
			
		||||
final class RcloneTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    protected function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        shell_exec('rclone test makefiles temp/source 2>&1');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        exec('rclone purge temp 2>&1', $output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function testRclonePath(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(\Exception::class);
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone('invalid');
 | 
			
		||||
        $this->assertString('', $rclone->getVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRcloneInvalidVersion(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->expectException(\Exception::class);
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone('uname');
 | 
			
		||||
        $this->assertString('', $rclone->getVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRcloneValidVersion(): void
 | 
			
		||||
    {
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone('./tests/mock-rclone');
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone();
 | 
			
		||||
        $this->assertStringContainsString('rclone', $rclone->getVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRcloneSize(): void
 | 
			
		||||
    {
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone();
 | 
			
		||||
        $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
 | 
			
		||||
    {
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone();
 | 
			
		||||
        $result = $rclone->copy('temp/source','temp/destination');
 | 
			
		||||
        $this->assertDirectoryExists('temp/destination');
 | 
			
		||||
 | 
			
		||||
        $rclone = new \App\Rclone\Rclone();
 | 
			
		||||
        $result = $rclone->copy('temp/source','temp/destination',['bwlimit'=>'6M']);
 | 
			
		||||
        $this->assertDirectoryExists('temp/destination');
 | 
			
		||||
        
 | 
			
		||||
        $this->expectException(\Exception::class);
 | 
			
		||||
        $this->expectExceptionMessage("ERROR");
 | 
			
		||||
        $result = $rclone->copy('temp/bogus-source','temp/bogus-destination');
 | 
			
		||||
        $this->assertDirectoryDoesNotExist('temp/bogus-destination');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
echo rclone v1.53.3-DEV
 | 
			
		||||
		Reference in New Issue
	
	Block a user