11<?php
22
3- namespace Illuminate \Tests \Cache ;
3+ namespace Illuminate \Tests \Integration \ Cache ;
44
5- use Illuminate \Cache \RateLimiter ;
6- use Illuminate \Cache \RedisStore ;
7- use Illuminate \Cache \Repository ;
85use Illuminate \Foundation \Application ;
96use Illuminate \Foundation \Testing \Concerns \InteractsWithRedis ;
107use Illuminate \Redis \RedisManager ;
1613use Redis ;
1714
1815#[RequiresPhpExtension('redis ' )]
19- class RedisCacheIntegrationTest extends TestCase
16+ class PhpRedisBackoffTest extends TestCase
2017{
2118 use InteractsWithRedis;
2219
2320 protected function setUp (): void
2421 {
2522 parent ::setUp ();
2623 $ this ->setUpRedis ();
24+
25+ $ client = $ this ->redis ['phpredis ' ]->connection ()->client ();
26+ if (! $ client instanceof Redis) {
27+ $ this ->markTestSkipped ('Backoff option is only supported with phpredis in non-cluster mode ' );
28+ }
2729 }
2830
2931 protected function tearDown (): void
@@ -32,64 +34,6 @@ protected function tearDown(): void
3234 $ this ->tearDownRedis ();
3335 }
3436
35- /**
36- * @param string $driver
37- */
38- #[DataProvider('redisDriverProvider ' )]
39- public function testRedisCacheAddTwice ($ driver )
40- {
41- $ store = new RedisStore ($ this ->redis [$ driver ]);
42- $ repository = new Repository ($ store );
43- $ this ->assertTrue ($ repository ->add ('k ' , 'v ' , 3600 ));
44- $ this ->assertFalse ($ repository ->add ('k ' , 'v ' , 3600 ));
45- $ this ->assertGreaterThan (3500 , $ this ->redis [$ driver ]->connection ()->ttl ('k ' ));
46- }
47-
48- /**
49- * @param string $driver
50- */
51- #[DataProvider('redisDriverProvider ' )]
52- public function testRedisCacheRateLimiter ($ driver )
53- {
54- $ store = new RedisStore ($ this ->redis [$ driver ]);
55- $ repository = new Repository ($ store );
56- $ rateLimiter = new RateLimiter ($ repository );
57-
58- $ this ->assertFalse ($ rateLimiter ->tooManyAttempts ('key ' , 1 ));
59- $ this ->assertEquals (1 , $ rateLimiter ->hit ('key ' , 60 ));
60- $ this ->assertTrue ($ rateLimiter ->tooManyAttempts ('key ' , 1 ));
61- $ this ->assertFalse ($ rateLimiter ->tooManyAttempts ('key ' , 2 ));
62- }
63-
64- /**
65- * Breaking change.
66- *
67- * @param string $driver
68- */
69- #[DataProvider('redisDriverProvider ' )]
70- public function testRedisCacheAddFalse ($ driver )
71- {
72- $ store = new RedisStore ($ this ->redis [$ driver ]);
73- $ repository = new Repository ($ store );
74- $ repository ->forever ('k ' , false );
75- $ this ->assertFalse ($ repository ->add ('k ' , 'v ' , 60 ));
76- $ this ->assertEquals (-1 , $ this ->redis [$ driver ]->connection ()->ttl ('k ' ));
77- }
78-
79- /**
80- * Breaking change.
81- *
82- * @param string $driver
83- */
84- #[DataProvider('redisDriverProvider ' )]
85- public function testRedisCacheAddNull ($ driver )
86- {
87- $ store = new RedisStore ($ this ->redis [$ driver ]);
88- $ repository = new Repository ($ store );
89- $ repository ->forever ('k ' , null );
90- $ this ->assertFalse ($ repository ->add ('k ' , 'v ' , 60 ));
91- }
92-
9337 #[DataProvider('phpRedisBackoffAlgorithmsProvider ' )]
9438 public function testPhpRedisBackoffAlgorithmParsing ($ friendlyAlgorithmName , $ expectedAlgorithm )
9539 {
0 commit comments