2022-07-31 04:52:27 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace RssBridge\Tests;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
final class UtilsTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testTruncate()
|
|
|
|
{
|
|
|
|
$this->assertSame('f...', truncate('foo', 1));
|
|
|
|
$this->assertSame('fo...', truncate('foo', 2));
|
|
|
|
$this->assertSame('foo', truncate('foo', 3));
|
|
|
|
$this->assertSame('foo', truncate('foo', 4));
|
|
|
|
$this->assertSame('fo[...]', truncate('foo', 2, '[...]'));
|
|
|
|
}
|
2022-08-06 23:46:28 +03:00
|
|
|
|
2022-09-04 05:35:21 +03:00
|
|
|
public function testFormatBytes()
|
|
|
|
{
|
|
|
|
$this->assertSame('1 B', format_bytes(1));
|
|
|
|
$this->assertSame('1 KB', format_bytes(1024));
|
|
|
|
$this->assertSame('1 MB', format_bytes(1024 ** 2));
|
|
|
|
$this->assertSame('1 GB', format_bytes(1024 ** 3));
|
|
|
|
$this->assertSame('1 TB', format_bytes(1024 ** 4));
|
|
|
|
}
|
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
public function testFileCache()
|
|
|
|
{
|
|
|
|
$sut = new \FileCache();
|
|
|
|
$sut->setScope('scope');
|
|
|
|
$sut->purgeCache(-1);
|
|
|
|
$sut->setKey(['key']);
|
|
|
|
|
|
|
|
$this->assertNull($sut->loadData());
|
|
|
|
|
|
|
|
$sut->saveData('data');
|
|
|
|
$this->assertSame('data', $sut->loadData());
|
|
|
|
$this->assertIsNumeric($sut->getTime());
|
|
|
|
$sut->purgeCache(-1);
|
|
|
|
}
|
2022-10-29 11:46:37 +03:00
|
|
|
|
|
|
|
public function testTrimFilePath()
|
|
|
|
{
|
|
|
|
$this->assertSame('', trim_path_prefix(dirname(__DIR__)));
|
|
|
|
$this->assertSame('tests', trim_path_prefix(__DIR__));
|
|
|
|
$this->assertSame('tests/UtilsTest.php', trim_path_prefix(__DIR__ . '/UtilsTest.php'));
|
|
|
|
}
|
2022-07-31 04:52:27 +03:00
|
|
|
}
|