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 }} diff --git a/tests/Cache/RedisCacheIntegrationTest.php b/tests/Integration/Cache/PhpRedisBackoffTest.php similarity index 64% rename from tests/Cache/RedisCacheIntegrationTest.php rename to tests/Integration/Cache/PhpRedisBackoffTest.php index aafa46a0404d..71f0a9cc6e50 100644 --- a/tests/Cache/RedisCacheIntegrationTest.php +++ b/tests/Integration/Cache/PhpRedisBackoffTest.php @@ -1,10 +1,7 @@ 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 @@ -32,64 +34,6 @@ protected function tearDown(): void $this->tearDownRedis(); } - /** - * @param string $driver - */ - #[DataProvider('redisDriverProvider')] - public function testRedisCacheAddTwice($driver) - { - $store = new RedisStore($this->redis[$driver]); - $repository = new Repository($store); - $this->assertTrue($repository->add('k', 'v', 3600)); - $this->assertFalse($repository->add('k', 'v', 3600)); - $this->assertGreaterThan(3500, $this->redis[$driver]->connection()->ttl('k')); - } - - /** - * @param string $driver - */ - #[DataProvider('redisDriverProvider')] - public function testRedisCacheRateLimiter($driver) - { - $store = new RedisStore($this->redis[$driver]); - $repository = new Repository($store); - $rateLimiter = new RateLimiter($repository); - - $this->assertFalse($rateLimiter->tooManyAttempts('key', 1)); - $this->assertEquals(1, $rateLimiter->hit('key', 60)); - $this->assertTrue($rateLimiter->tooManyAttempts('key', 1)); - $this->assertFalse($rateLimiter->tooManyAttempts('key', 2)); - } - - /** - * Breaking change. - * - * @param string $driver - */ - #[DataProvider('redisDriverProvider')] - public function testRedisCacheAddFalse($driver) - { - $store = new RedisStore($this->redis[$driver]); - $repository = new Repository($store); - $repository->forever('k', false); - $this->assertFalse($repository->add('k', 'v', 60)); - $this->assertEquals(-1, $this->redis[$driver]->connection()->ttl('k')); - } - - /** - * Breaking change. - * - * @param string $driver - */ - #[DataProvider('redisDriverProvider')] - public function testRedisCacheAddNull($driver) - { - $store = new RedisStore($this->redis[$driver]); - $repository = new Repository($store); - $repository->forever('k', null); - $this->assertFalse($repository->add('k', 'v', 60)); - } - #[DataProvider('phpRedisBackoffAlgorithmsProvider')] public function testPhpRedisBackoffAlgorithmParsing($friendlyAlgorithmName, $expectedAlgorithm) { diff --git a/tests/Integration/Cache/RedisCacheIntegrationTest.php b/tests/Integration/Cache/RedisCacheIntegrationTest.php new file mode 100644 index 000000000000..76226569493e --- /dev/null +++ b/tests/Integration/Cache/RedisCacheIntegrationTest.php @@ -0,0 +1,87 @@ +setUpRedis(); + } + + protected function tearDown(): void + { + parent::tearDown(); + $this->tearDownRedis(); + } + + /** + * @param string $driver + */ + #[DataProvider('redisDriverProvider')] + public function testRedisCacheAddTwice($driver) + { + $store = new RedisStore($this->redis[$driver]); + $repository = new Repository($store); + $this->assertTrue($repository->add('k', 'v', 3600)); + $this->assertFalse($repository->add('k', 'v', 3600)); + $this->assertGreaterThan(3500, $this->redis[$driver]->connection()->ttl('k')); + } + + /** + * @param string $driver + */ + #[DataProvider('redisDriverProvider')] + public function testRedisCacheRateLimiter($driver) + { + $store = new RedisStore($this->redis[$driver]); + $repository = new Repository($store); + $rateLimiter = new RateLimiter($repository); + + $this->assertFalse($rateLimiter->tooManyAttempts('key', 1)); + $this->assertEquals(1, $rateLimiter->hit('key', 60)); + $this->assertTrue($rateLimiter->tooManyAttempts('key', 1)); + $this->assertFalse($rateLimiter->tooManyAttempts('key', 2)); + } + + /** + * Breaking change. + * + * @param string $driver + */ + #[DataProvider('redisDriverProvider')] + public function testRedisCacheAddFalse($driver) + { + $store = new RedisStore($this->redis[$driver]); + $repository = new Repository($store); + $repository->forever('k', false); + $this->assertFalse($repository->add('k', 'v', 60)); + $this->assertEquals(-1, $this->redis[$driver]->connection()->ttl('k')); + } + + /** + * Breaking change. + * + * @param string $driver + */ + #[DataProvider('redisDriverProvider')] + public function testRedisCacheAddNull($driver) + { + $store = new RedisStore($this->redis[$driver]); + $repository = new Repository($store); + $repository->forever('k', null); + $this->assertFalse($repository->add('k', 'v', 60)); + } +}