diff --git a/composer.json b/composer.json index 327e025..883033b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "furyfire/backupscript", - "description": "Wrapper for Rclone based backup", + "description": "Wrapper for Rclone based backup with push notifications", "homepage": "https://jcktrue.dk", "version": "0.1.0", "require": { diff --git a/composer.lock b/composer.lock index 80304e4..7b96069 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7c0718c0e4c6eabc3fec9cc0dbf816e2", + "content-hash": "545ed8a092dd0e7cb6c11837968dafc7", "packages": [ { "name": "dflydev/dot-access-data", diff --git a/src/App.php b/src/App.php index 75655f7..0d463e2 100644 --- a/src/App.php +++ b/src/App.php @@ -1,5 +1,7 @@ - * @license https://opensource.org/licenses/gpl-license.php GNU Public License - * @link https://jcktrue.dk */ class App { + /// Logging instance protected Logger $logger; + /// Configuration singleton protected Configuration $config; /** - * Create a new instance providing a config file + * Create a new instance providing a config file. * * @param string $configFile Relative or full path to YML config. * @SuppressWarnings(PHPMD.StaticAccess) diff --git a/src/CommandBackup.php b/src/CommandBackup.php index a663bc2..8504f34 100644 --- a/src/CommandBackup.php +++ b/src/CommandBackup.php @@ -1,5 +1,7 @@ expectException(\Exception::class); + new App('no_file'); + $this->fail('Exception was not thrown'); + } + + public function testGoodConfig(): void + { + $app = new App('config.example.yml'); + $this->assertEquals('output.log', $app->getConfig('log')); + $this->assertInstanceOf(LoggerInterface::class, $app->getLogger()); + } +} diff --git a/tests/Rclone/RcloneTest.php b/tests/Rclone/RcloneTest.php index 4d7b25d..61be9df 100644 --- a/tests/Rclone/RcloneTest.php +++ b/tests/Rclone/RcloneTest.php @@ -23,15 +23,15 @@ final class RcloneTest extends TestCase public function testRclonePath(): void { $this->expectException(\Exception::class); - $rclone = new Rclone('invalid'); - $this->assertEquals('', $rclone->getVersion()); + new Rclone('invalid'); + $this->fail('Exception was not thrown'); } public function testRcloneInvalidVersion(): void { $this->expectException(\Exception::class); - $rclone = new Rclone('uname'); - $this->assertEquals('', $rclone->getVersion()); + new Rclone('uname'); + $this->fail('Exception was not thrown'); } public function testRcloneValidVersion(): void @@ -49,7 +49,7 @@ final class RcloneTest extends TestCase $this->expectException(\Exception::class); $this->expectExceptionMessage("ERROR"); $size = $rclone->getSize('temp/bogus-source'); - $this->assertEquals(0, $size); + $this->fail('Exception was not thrown'); } public function testRcloneCopy(): void @@ -65,6 +65,6 @@ final class RcloneTest extends TestCase $this->expectException(\Exception::class); $this->expectExceptionMessage("ERROR"); $rclone->copy('temp/bogus-source', 'temp/bogus-destination'); - $this->assertDirectoryDoesNotExist('temp/bogus-destination'); + $this->fail('Exception was not thrown'); } } diff --git a/tests/Template/TwigExtensionTest.php b/tests/Template/TwigExtensionTest.php new file mode 100644 index 0000000..92e5438 --- /dev/null +++ b/tests/Template/TwigExtensionTest.php @@ -0,0 +1,36 @@ +getFilters(); + $this->assertContainsOnlyInstancesOf(TwigFilter::class, $filters); + } + + + public function testformatBytes(): void + { + $obj = new TwigExtension(); + $this->assertEquals('1.00B', $obj->formatBytes(1, 2)); + $this->assertEquals('2.00B', $obj->formatBytes(2, 2)); + $this->assertEquals('10.00B', $obj->formatBytes(10, 2)); + $this->assertEquals('0.98kB', $obj->formatBytes(1000, 2)); + $this->assertEquals('1.00kB', $obj->formatBytes(1024, 2)); + $this->assertEquals('512.00MB', $obj->formatBytes(1024 ** 3 / 2, 2)); + $this->assertEquals('1.00GB', $obj->formatBytes(1024 ** 3 - 1, 2)); + $this->assertEquals('1.00GB', $obj->formatBytes(1024 ** 3, 2)); + $this->assertEquals('512.00GB', $obj->formatBytes(1024 ** 4 / 2, 2)); + $this->assertEquals('1.00TB', $obj->formatBytes(1024 ** 4, 2)); + } +}