diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index c868f34550e9..3a70d1f647bb 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -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; diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 05cae32da440..5b55f5a99732 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -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; diff --git a/tests/system/Cache/Handlers/ApcuHandlerTest.php b/tests/system/Cache/Handlers/ApcuHandlerTest.php index 5d5d5f7b2f6f..e52897e96b5c 100644 --- a/tests/system/Cache/Handlers/ApcuHandlerTest.php +++ b/tests/system/Cache/Handlers/ApcuHandlerTest.php @@ -27,30 +27,24 @@ #[RequiresPhpExtension('apcu')] final class ApcuHandlerTest extends AbstractHandlerTestCase { - /** - * @return list - */ - 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 diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index c4fa8481bbd4..3752d8a74cd3 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -31,18 +31,6 @@ final class FileHandlerTest extends AbstractHandlerTestCase private static string $directory = 'FileHandler'; private Cache $config; - /** - * @return list - */ - private static function getKeyArray(): array - { - return [ - self::$key1, - self::$key2, - self::$key3, - ]; - } - protected function setUp(): void { parent::setUp(); @@ -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']); @@ -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)); diff --git a/tests/system/Cache/Handlers/MemcachedHandlerTest.php b/tests/system/Cache/Handlers/MemcachedHandlerTest.php index e6bd5dd147ec..d64dd2c8afb3 100644 --- a/tests/system/Cache/Handlers/MemcachedHandlerTest.php +++ b/tests/system/Cache/Handlers/MemcachedHandlerTest.php @@ -26,18 +26,6 @@ #[Group('CacheLive')] final class MemcachedHandlerTest extends AbstractHandlerTestCase { - /** - * @return list - */ - private static function getKeyArray(): array - { - return [ - self::$key1, - self::$key2, - self::$key3, - ]; - } - protected function setUp(): void { parent::setUp(); @@ -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 diff --git a/tests/system/Cache/Handlers/PredisHandlerTest.php b/tests/system/Cache/Handlers/PredisHandlerTest.php index 135d3ff083de..69dedb0591ad 100644 --- a/tests/system/Cache/Handlers/PredisHandlerTest.php +++ b/tests/system/Cache/Handlers/PredisHandlerTest.php @@ -27,18 +27,6 @@ final class PredisHandlerTest extends AbstractHandlerTestCase { private Cache $config; - /** - * @return list - */ - private static function getKeyArray(): array - { - return [ - self::$key1, - self::$key2, - self::$key3, - ]; - } - protected function setUp(): void { parent::setUp(); @@ -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 diff --git a/tests/system/Cache/Handlers/RedisHandlerTest.php b/tests/system/Cache/Handlers/RedisHandlerTest.php index d42123c6dd82..9fe0350255f2 100644 --- a/tests/system/Cache/Handlers/RedisHandlerTest.php +++ b/tests/system/Cache/Handlers/RedisHandlerTest.php @@ -28,18 +28,6 @@ final class RedisHandlerTest extends AbstractHandlerTestCase { private Cache $config; - /** - * @return list - */ - private static function getKeyArray(): array - { - return [ - self::$key1, - self::$key2, - self::$key3, - ]; - } - protected function setUp(): void { parent::setUp(); @@ -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