2023-03-20 21:10:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RssBridge\Tests;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class CacheTest extends TestCase
|
|
|
|
{
|
2023-06-30 23:31:19 +03:00
|
|
|
public function testConfig()
|
|
|
|
{
|
2023-09-21 23:05:55 +03:00
|
|
|
$sut = new \FileCache(new \NullLogger(), ['path' => '/tmp/']);
|
2023-06-30 23:31:19 +03:00
|
|
|
$this->assertSame(['path' => '/tmp/', 'enable_purge' => true], $sut->getConfig());
|
|
|
|
|
2023-09-21 23:05:55 +03:00
|
|
|
$sut = new \FileCache(new \NullLogger(), ['path' => '/', 'enable_purge' => false]);
|
2023-06-30 23:31:19 +03:00
|
|
|
$this->assertSame(['path' => '/', 'enable_purge' => false], $sut->getConfig());
|
|
|
|
|
2023-09-21 23:05:55 +03:00
|
|
|
$sut = new \FileCache(new \NullLogger(), ['path' => '/tmp', 'enable_purge' => true]);
|
2023-06-30 23:31:19 +03:00
|
|
|
$this->assertSame(['path' => '/tmp/', 'enable_purge' => true], $sut->getConfig());
|
|
|
|
}
|
|
|
|
|
2023-03-20 21:10:01 +03:00
|
|
|
public function testFileCache()
|
|
|
|
{
|
|
|
|
$temporaryFolder = sprintf('%s/rss_bridge_%s/', sys_get_temp_dir(), create_random_string());
|
|
|
|
mkdir($temporaryFolder);
|
|
|
|
|
2023-09-21 23:05:55 +03:00
|
|
|
$sut = new \FileCache(new \NullLogger(), [
|
2023-03-20 21:10:01 +03:00
|
|
|
'path' => $temporaryFolder,
|
|
|
|
'enable_purge' => true,
|
|
|
|
]);
|
2023-09-10 22:50:15 +03:00
|
|
|
$sut->clear();
|
2023-03-20 21:10:01 +03:00
|
|
|
|
2023-09-10 22:50:15 +03:00
|
|
|
$this->assertNull($sut->get('key'));
|
2023-03-20 21:10:01 +03:00
|
|
|
|
2023-09-10 22:50:15 +03:00
|
|
|
$sut->set('key', 'data', 5);
|
|
|
|
$this->assertSame('data', $sut->get('key'));
|
|
|
|
$sut->clear();
|
2023-03-20 21:10:01 +03:00
|
|
|
|
|
|
|
// Intentionally not deleting the temp folder
|
|
|
|
}
|
|
|
|
}
|