From 7a6e71dc6c8c929b855c3715ce8e23f61f6946cc Mon Sep 17 00:00:00 2001 From: Jens True Date: Wed, 31 May 2023 10:12:52 +0000 Subject: [PATCH] Mock Rclone installation --- src/Rclone/Rclone.php | 8 +++++++- tests/Rclone/RcloneTest.php | 15 ++++++++++----- tests/mock-rclone | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100755 tests/mock-rclone 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