diff --git a/src/Rclone/Rclone.php b/src/Rclone/Rclone.php index 689200e..d00a214 100644 --- a/src/Rclone/Rclone.php +++ b/src/Rclone/Rclone.php @@ -24,11 +24,17 @@ class Rclone try { $version = $this->exec('--version'); - $this->version = explode("\n", $version)[0]; } catch(ProcessFailedException $e) { throw new Exception("Check installation of rclone"); + return; + } + + $this->version = explode("\n", $version)[0]; + + if (!\str_contains($this->version, 'rclone')) { + throw new Exception("Rclone not recognized"); } } diff --git a/tests/Rclone/RcloneTest.php b/tests/Rclone/RcloneTest.php index fe3c829..89b44ef 100644 --- a/tests/Rclone/RcloneTest.php +++ b/tests/Rclone/RcloneTest.php @@ -3,16 +3,21 @@ use PHPUnit\Framework\TestCase; final class RcloneTest extends TestCase { - public function testExceptionOnInvalidRclonePath(): void + public function testRclonePath(): void { $this->expectException(\Exception::class); $rclone = new \App\Rclone\Rclone('invalid'); } - - public function testRcloneVersion(): void + public function testRcloneInvalidVersion(): void { - $rclone = new \App\Rclone\Rclone(); - $this->assertStringContainsString('rclone', $rclone->getversion()); + $this->expectException(\Exception::class); + $rclone = new \App\Rclone\Rclone('uname'); + } + + public function testRcloneValidVersion(): void + { + $rclone = new \App\Rclone\Rclone('./tests/mock-rclone'); + $this->assertStringContainsString('rclone', $rclone->getVersion()); } } \ No newline at end of file diff --git a/tests/mock-rclone b/tests/mock-rclone new file mode 100755 index 0000000..645f1a3 --- /dev/null +++ b/tests/mock-rclone @@ -0,0 +1,2 @@ +#!/bin/bash +echo rclone v1.53.3-DEV