Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function save(string $key, mixed $value, int $ttl = 60): bool
}

if ($ttl !== 0) {
$this->redis->expireat($key, Time::now()->getTimestamp() + $ttl);
$this->redis->expire($key, $ttl);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function save(string $key, mixed $value, int $ttl = 60): bool
}

if ($ttl !== 0) {
$this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl);
$this->redis->expire($key, $ttl);
}

return true;
Expand Down
22 changes: 8 additions & 14 deletions tests/system/Cache/Handlers/ApcuHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,24 @@
#[RequiresPhpExtension('apcu')]
final class ApcuHandlerTest extends AbstractHandlerTestCase
{
/**
* @return list<string>
*/
private static function getKeyArray(): array
{
return [
self::$key1,
self::$key2,
self::$key3,
];
}

protected function setUp(): void
{
parent::setUp();

if (! function_exists('apcu_enabled') || ! apcu_enabled()) {
$this->markTestSkipped('APCu extension is not loaded or not enabled in CLI.');
}

$this->handler = CacheFactory::getHandler(new Cache(), 'apcu');
}

protected function tearDown(): void
{
foreach (self::getKeyArray() as $key) {
$this->handler->delete($key);
if (! isset($this->handler)) {
return;
}

$this->handler->clean();
}

public function testNew(): void
Expand Down
26 changes: 4 additions & 22 deletions tests/system/Cache/Handlers/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ final class FileHandlerTest extends AbstractHandlerTestCase
private static string $directory = 'FileHandler';
private Cache $config;

/**
* @return list<string>
*/
private static function getKeyArray(): array
{
return [
self::$key1,
self::$key2,
self::$key3,
];
}

protected function setUp(): void
{
parent::setUp();
Expand All @@ -65,19 +53,13 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
clearstatcache();

if (is_dir($this->config->file['storePath'])) {
chmod($this->config->file['storePath'], 0777);

foreach (self::getKeyArray() as $key) {
if (is_file($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $key)) {
chmod($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $key, 0777);
unlink($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $key);
}
if (is_file($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $this->config->prefix . $key)) {
chmod($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $this->config->prefix . $key, 0777);
unlink($this->config->file['storePath'] . DIRECTORY_SEPARATOR . $this->config->prefix . $key);
}
if (isset($this->handler)) {
$this->handler->clean();
}

rmdir($this->config->file['storePath']);
Expand Down Expand Up @@ -118,7 +100,7 @@ public function testSetDefaultPath(): void
*/
public function testGet(): void
{
$this->handler->save(self::$key1, 'value', 2);
$this->assertTrue($this->handler->save(self::$key1, 'value', 2));

$this->assertSame('value', $this->handler->get(self::$key1));
$this->assertNull($this->handler->get(self::$dummy));
Expand Down
18 changes: 4 additions & 14 deletions tests/system/Cache/Handlers/MemcachedHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@
#[Group('CacheLive')]
final class MemcachedHandlerTest extends AbstractHandlerTestCase
{
/**
* @return list<string>
*/
private static function getKeyArray(): array
{
return [
self::$key1,
self::$key2,
self::$key3,
];
}

protected function setUp(): void
{
parent::setUp();
Expand All @@ -51,9 +39,11 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach (self::getKeyArray() as $key) {
$this->handler->delete($key);
if (! isset($this->handler)) {
return;
}

$this->handler->clean();
}

public function testNew(): void
Expand Down
18 changes: 4 additions & 14 deletions tests/system/Cache/Handlers/PredisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ final class PredisHandlerTest extends AbstractHandlerTestCase
{
private Cache $config;

/**
* @return list<string>
*/
private static function getKeyArray(): array
{
return [
self::$key1,
self::$key2,
self::$key3,
];
}

protected function setUp(): void
{
parent::setUp();
Expand All @@ -49,9 +37,11 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach (self::getKeyArray() as $key) {
$this->handler->delete($key);
if (! isset($this->handler)) {
return;
}

$this->handler->clean();
}

public function testNew(): void
Expand Down
18 changes: 4 additions & 14 deletions tests/system/Cache/Handlers/RedisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ final class RedisHandlerTest extends AbstractHandlerTestCase
{
private Cache $config;

/**
* @return list<string>
*/
private static function getKeyArray(): array
{
return [
self::$key1,
self::$key2,
self::$key3,
];
}

protected function setUp(): void
{
parent::setUp();
Expand All @@ -54,9 +42,11 @@ protected function setUp(): void

protected function tearDown(): void
{
foreach (self::getKeyArray() as $key) {
$this->handler->delete($key);
if (! isset($this->handler)) {
return;
}

$this->handler->clean();
}

public function testNew(): void
Expand Down
Loading