Quality of life improvements all around.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
28
tests/AppTest.php
Normal file
28
tests/AppTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\App;
|
||||
|
||||
#[CoversClass(App::class)]
|
||||
final class AppTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testNonexistentConfigFile(): void
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
36
tests/Template/TwigExtensionTest.php
Normal file
36
tests/Template/TwigExtensionTest.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use App\Template\TwigExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
final class TwigExtensionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetFilters(): void
|
||||
{
|
||||
$obj = new TwigExtension();
|
||||
$filters = $obj->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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user