From 8f3277a29a02051e1a6f4a8a59c515db2ef80fb4 Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 22 Nov 2025 10:32:04 +0700 Subject: [PATCH 1/3] [12.x] moving RedisCacheIntegrationTest to Integration tests --- tests/{ => Integration}/Cache/RedisCacheIntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{ => Integration}/Cache/RedisCacheIntegrationTest.php (99%) diff --git a/tests/Cache/RedisCacheIntegrationTest.php b/tests/Integration/Cache/RedisCacheIntegrationTest.php similarity index 99% rename from tests/Cache/RedisCacheIntegrationTest.php rename to tests/Integration/Cache/RedisCacheIntegrationTest.php index aafa46a0404d..fcbdb38ae37c 100644 --- a/tests/Cache/RedisCacheIntegrationTest.php +++ b/tests/Integration/Cache/RedisCacheIntegrationTest.php @@ -1,6 +1,6 @@ Date: Sat, 22 Nov 2025 11:23:22 +0700 Subject: [PATCH 2/3] [12.x] CACHE_STORE env for Redis Cache tests --- .github/workflows/redis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/redis.yml b/.github/workflows/redis.yml index cb5dda5c095c..e385902b3900 100644 --- a/.github/workflows/redis.yml +++ b/.github/workflows/redis.yml @@ -50,6 +50,7 @@ jobs: - name: Execute Cache tests run: vendor/bin/phpunit tests/Integration/Cache env: + CACHE_STORE: redis REDIS_CACHE_CONNECTION: cache REDIS_CACHE_LOCK_CONNECTION: cache REDIS_CLIENT: ${{ matrix.client }} @@ -117,6 +118,7 @@ jobs: - name: Execute Cache tests run: vendor/bin/phpunit tests/Integration/Cache env: + CACHE_STORE: redis REDIS_CACHE_CONNECTION: default REDIS_CACHE_LOCK_CONNECTION: default REDIS_CLIENT: ${{ matrix.client }} From cdd729c418dd8d6260c461079dd3e7ebfdd0d559 Mon Sep 17 00:00:00 2001 From: Vadim Dvorovenko Date: Sat, 22 Nov 2025 13:48:32 +0700 Subject: [PATCH 3/3] [12.x] extract Backoff test to separate test --- .../Integration/Cache/PhpRedisBackoffTest.php | 128 ++++++++++++++++++ .../Cache/RedisCacheIntegrationTest.php | 97 ------------- 2 files changed, 128 insertions(+), 97 deletions(-) create mode 100644 tests/Integration/Cache/PhpRedisBackoffTest.php diff --git a/tests/Integration/Cache/PhpRedisBackoffTest.php b/tests/Integration/Cache/PhpRedisBackoffTest.php new file mode 100644 index 000000000000..71f0a9cc6e50 --- /dev/null +++ b/tests/Integration/Cache/PhpRedisBackoffTest.php @@ -0,0 +1,128 @@ +setUpRedis(); + + $client = $this->redis['phpredis']->connection()->client(); + if (! $client instanceof Redis) { + $this->markTestSkipped('Backoff option is only supported with phpredis in non-cluster mode'); + } + } + + protected function tearDown(): void + { + parent::tearDown(); + $this->tearDownRedis(); + } + + #[DataProvider('phpRedisBackoffAlgorithmsProvider')] + public function testPhpRedisBackoffAlgorithmParsing($friendlyAlgorithmName, $expectedAlgorithm) + { + $host = Env::get('REDIS_HOST', '127.0.0.1'); + $port = Env::get('REDIS_PORT', 6379); + + $manager = new RedisManager(new Application(), 'phpredis', [ + 'default' => [ + 'host' => $host, + 'port' => $port, + 'backoff_algorithm' => $friendlyAlgorithmName, + ], + ]); + + $this->assertEquals( + $expectedAlgorithm, + $manager->connection()->client()->getOption(Redis::OPT_BACKOFF_ALGORITHM) + ); + } + + #[DataProvider('phpRedisBackoffAlgorithmsProvider')] + public function testPhpRedisBackoffAlgorithm($friendlyAlgorithm, $expectedAlgorithm) + { + $host = Env::get('REDIS_HOST', '127.0.0.1'); + $port = Env::get('REDIS_PORT', 6379); + + $manager = new RedisManager(new Application(), 'phpredis', [ + 'default' => [ + 'host' => $host, + 'port' => $port, + 'backoff_algorithm' => $expectedAlgorithm, + ], + ]); + + $this->assertEquals( + $expectedAlgorithm, + $manager->connection()->client()->getOption(Redis::OPT_BACKOFF_ALGORITHM) + ); + } + + public function testAnInvalidPhpRedisBackoffAlgorithmIsConvertedToDefault() + { + $host = Env::get('REDIS_HOST', '127.0.0.1'); + $port = Env::get('REDIS_PORT', 6379); + + $manager = new RedisManager(new Application(), 'phpredis', [ + 'default' => [ + 'host' => $host, + 'port' => $port, + 'backoff_algorithm' => 7, + ], + ]); + + $this->assertEquals( + Redis::BACKOFF_ALGORITHM_DEFAULT, + $manager->connection()->client()->getOption(Redis::OPT_BACKOFF_ALGORITHM) + ); + } + + public function testItFailsWithAnInvalidPhpRedisAlgorithm() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Algorithm [foo] is not a valid PhpRedis backoff algorithm'); + + $host = Env::get('REDIS_HOST', '127.0.0.1'); + $port = Env::get('REDIS_PORT', 6379); + + (new RedisManager(new Application(), 'phpredis', [ + 'default' => [ + 'host' => $host, + 'port' => $port, + 'backoff_algorithm' => 'foo', + ], + ]))->connection(); + } + + public static function phpRedisBackoffAlgorithmsProvider() + { + if (! class_exists(Redis::class)) { + return []; + } + + return [ + ['default', Redis::BACKOFF_ALGORITHM_DEFAULT], + ['decorrelated_jitter', Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER], + ['equal_jitter', Redis::BACKOFF_ALGORITHM_EQUAL_JITTER], + ['exponential', Redis::BACKOFF_ALGORITHM_EXPONENTIAL], + ['uniform', Redis::BACKOFF_ALGORITHM_UNIFORM], + ['constant', Redis::BACKOFF_ALGORITHM_CONSTANT], + ]; + } +} diff --git a/tests/Integration/Cache/RedisCacheIntegrationTest.php b/tests/Integration/Cache/RedisCacheIntegrationTest.php index fcbdb38ae37c..76226569493e 100644 --- a/tests/Integration/Cache/RedisCacheIntegrationTest.php +++ b/tests/Integration/Cache/RedisCacheIntegrationTest.php @@ -5,15 +5,10 @@ use Illuminate\Cache\RateLimiter; use Illuminate\Cache\RedisStore; use Illuminate\Cache\Repository; -use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; -use Illuminate\Redis\RedisManager; -use Illuminate\Support\Env; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; -use Redis; #[RequiresPhpExtension('redis')] class RedisCacheIntegrationTest extends TestCase @@ -89,96 +84,4 @@ public function testRedisCacheAddNull($driver) $repository->forever('k', null); $this->assertFalse($repository->add('k', 'v', 60)); } - - #[DataProvider('phpRedisBackoffAlgorithmsProvider')] - public function testPhpRedisBackoffAlgorithmParsing($friendlyAlgorithmName, $expectedAlgorithm) - { - $host = Env::get('REDIS_HOST', '127.0.0.1'); - $port = Env::get('REDIS_PORT', 6379); - - $manager = new RedisManager(new Application(), 'phpredis', [ - 'default' => [ - 'host' => $host, - 'port' => $port, - 'backoff_algorithm' => $friendlyAlgorithmName, - ], - ]); - - $this->assertEquals( - $expectedAlgorithm, - $manager->connection()->client()->getOption(Redis::OPT_BACKOFF_ALGORITHM) - ); - } - - #[DataProvider('phpRedisBackoffAlgorithmsProvider')] - public function testPhpRedisBackoffAlgorithm($friendlyAlgorithm, $expectedAlgorithm) - { - $host = Env::get('REDIS_HOST', '127.0.0.1'); - $port = Env::get('REDIS_PORT', 6379); - - $manager = new RedisManager(new Application(), 'phpredis', [ - 'default' => [ - 'host' => $host, - 'port' => $port, - 'backoff_algorithm' => $expectedAlgorithm, - ], - ]); - - $this->assertEquals( - $expectedAlgorithm, - $manager->connection()->client()->getOption(Redis::OPT_BACKOFF_ALGORITHM) - ); - } - - public function testAnInvalidPhpRedisBackoffAlgorithmIsConvertedToDefault() - { - $host = Env::get('REDIS_HOST', '127.0.0.1'); - $port = Env::get('REDIS_PORT', 6379); - - $manager = new RedisManager(new Application(), 'phpredis', [ - 'default' => [ - 'host' => $host, - 'port' => $port, - 'backoff_algorithm' => 7, - ], - ]); - - $this->assertEquals( - Redis::BACKOFF_ALGORITHM_DEFAULT, - $manager->connection()->client()->getOption(Redis::OPT_BACKOFF_ALGORITHM) - ); - } - - public function testItFailsWithAnInvalidPhpRedisAlgorithm() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Algorithm [foo] is not a valid PhpRedis backoff algorithm'); - - $host = Env::get('REDIS_HOST', '127.0.0.1'); - $port = Env::get('REDIS_PORT', 6379); - - (new RedisManager(new Application(), 'phpredis', [ - 'default' => [ - 'host' => $host, - 'port' => $port, - 'backoff_algorithm' => 'foo', - ], - ]))->connection(); - } - - public static function phpRedisBackoffAlgorithmsProvider() - { - if (! class_exists(Redis::class)) { - return []; - } - - return [ - ['default', Redis::BACKOFF_ALGORITHM_DEFAULT], - ['decorrelated_jitter', Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER], - ['equal_jitter', Redis::BACKOFF_ALGORITHM_EQUAL_JITTER], - ['exponential', Redis::BACKOFF_ALGORITHM_EXPONENTIAL], - ['uniform', Redis::BACKOFF_ALGORITHM_UNIFORM], - ['constant', Redis::BACKOFF_ALGORITHM_CONSTANT], - ]; - } }