mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-09 01:56:39 +02:00
feat: add config option "path" for file cache (#3297)
This commit is contained in:
31
tests/CacheTest.php
Normal file
31
tests/CacheTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace RssBridge\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CacheTest extends TestCase
|
||||
{
|
||||
public function testFileCache()
|
||||
{
|
||||
$temporaryFolder = sprintf('%s/rss_bridge_%s/', sys_get_temp_dir(), create_random_string());
|
||||
mkdir($temporaryFolder);
|
||||
|
||||
$sut = new \FileCache([
|
||||
'path' => $temporaryFolder,
|
||||
'enable_purge' => true,
|
||||
]);
|
||||
$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);
|
||||
|
||||
// Intentionally not deleting the temp folder
|
||||
}
|
||||
}
|
@@ -26,21 +26,6 @@ final class UtilsTest extends TestCase
|
||||
$this->assertSame('1 TB', format_bytes(1024 ** 4));
|
||||
}
|
||||
|
||||
public function testFileCache()
|
||||
{
|
||||
$sut = new \FileCache(['enable_purge' => true]);
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testSanitizePathName()
|
||||
{
|
||||
$this->assertSame('index.php', _sanitize_path_name('/home/satoshi/rss-bridge/index.php', '/home/satoshi/rss-bridge'));
|
||||
@@ -54,4 +39,11 @@ final class UtilsTest extends TestCase
|
||||
$sanitized = 'Error: Argument 1 passed to foo() must be an instance of kk, string given, called in bridges/RumbleBridge.php';
|
||||
$this->assertSame($sanitized, _sanitize_path_name($raw, '/home/satoshi/rss-bridge'));
|
||||
}
|
||||
|
||||
public function testCreateRandomString()
|
||||
{
|
||||
$this->assertSame(2, strlen(create_random_string(1)));
|
||||
$this->assertSame(4, strlen(create_random_string(2)));
|
||||
$this->assertSame(6, strlen(create_random_string(3)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user