Skip to content

Commit 976d0a8

Browse files
authored
[12.x] Moving redis integration tests (#57860)
* [12.x] moving RedisCacheIntegrationTest to Integration tests * [12.x] CACHE_STORE env for Redis Cache tests * [12.x] extract Backoff test to separate test
1 parent 5583b8e commit 976d0a8

File tree

3 files changed

+96
-63
lines changed

3 files changed

+96
-63
lines changed

.github/workflows/redis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
- name: Execute Cache tests
5151
run: vendor/bin/phpunit tests/Integration/Cache
5252
env:
53+
CACHE_STORE: redis
5354
REDIS_CACHE_CONNECTION: cache
5455
REDIS_CACHE_LOCK_CONNECTION: cache
5556
REDIS_CLIENT: ${{ matrix.client }}
@@ -117,6 +118,7 @@ jobs:
117118
- name: Execute Cache tests
118119
run: vendor/bin/phpunit tests/Integration/Cache
119120
env:
121+
CACHE_STORE: redis
120122
REDIS_CACHE_CONNECTION: default
121123
REDIS_CACHE_LOCK_CONNECTION: default
122124
REDIS_CLIENT: ${{ matrix.client }}

tests/Cache/RedisCacheIntegrationTest.php renamed to tests/Integration/Cache/PhpRedisBackoffTest.php

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
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;
85
use Illuminate\Foundation\Application;
96
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
107
use Illuminate\Redis\RedisManager;
@@ -16,14 +13,19 @@
1613
use 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
{
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Cache;
4+
5+
use Illuminate\Cache\RateLimiter;
6+
use Illuminate\Cache\RedisStore;
7+
use Illuminate\Cache\Repository;
8+
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
9+
use PHPUnit\Framework\Attributes\DataProvider;
10+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
11+
use PHPUnit\Framework\TestCase;
12+
13+
#[RequiresPhpExtension('redis')]
14+
class RedisCacheIntegrationTest extends TestCase
15+
{
16+
use InteractsWithRedis;
17+
18+
protected function setUp(): void
19+
{
20+
parent::setUp();
21+
$this->setUpRedis();
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
parent::tearDown();
27+
$this->tearDownRedis();
28+
}
29+
30+
/**
31+
* @param string $driver
32+
*/
33+
#[DataProvider('redisDriverProvider')]
34+
public function testRedisCacheAddTwice($driver)
35+
{
36+
$store = new RedisStore($this->redis[$driver]);
37+
$repository = new Repository($store);
38+
$this->assertTrue($repository->add('k', 'v', 3600));
39+
$this->assertFalse($repository->add('k', 'v', 3600));
40+
$this->assertGreaterThan(3500, $this->redis[$driver]->connection()->ttl('k'));
41+
}
42+
43+
/**
44+
* @param string $driver
45+
*/
46+
#[DataProvider('redisDriverProvider')]
47+
public function testRedisCacheRateLimiter($driver)
48+
{
49+
$store = new RedisStore($this->redis[$driver]);
50+
$repository = new Repository($store);
51+
$rateLimiter = new RateLimiter($repository);
52+
53+
$this->assertFalse($rateLimiter->tooManyAttempts('key', 1));
54+
$this->assertEquals(1, $rateLimiter->hit('key', 60));
55+
$this->assertTrue($rateLimiter->tooManyAttempts('key', 1));
56+
$this->assertFalse($rateLimiter->tooManyAttempts('key', 2));
57+
}
58+
59+
/**
60+
* Breaking change.
61+
*
62+
* @param string $driver
63+
*/
64+
#[DataProvider('redisDriverProvider')]
65+
public function testRedisCacheAddFalse($driver)
66+
{
67+
$store = new RedisStore($this->redis[$driver]);
68+
$repository = new Repository($store);
69+
$repository->forever('k', false);
70+
$this->assertFalse($repository->add('k', 'v', 60));
71+
$this->assertEquals(-1, $this->redis[$driver]->connection()->ttl('k'));
72+
}
73+
74+
/**
75+
* Breaking change.
76+
*
77+
* @param string $driver
78+
*/
79+
#[DataProvider('redisDriverProvider')]
80+
public function testRedisCacheAddNull($driver)
81+
{
82+
$store = new RedisStore($this->redis[$driver]);
83+
$repository = new Repository($store);
84+
$repository->forever('k', null);
85+
$this->assertFalse($repository->add('k', 'v', 60));
86+
}
87+
}

0 commit comments

Comments
 (0)