Skip to content

Commit 95c2454

Browse files
committed
Improve test suite related to redis
- Added data providers to allow testing of different redis connection configurations. - All tests using redis are now using data providers to test all relevant redis connection settings separately making it easy to pinpoint which redis setting causes an issue with a specific component. Signed-off-by: Petr Levtonov <[email protected]>
1 parent eb00c1b commit 95c2454

14 files changed

+1435
-1375
lines changed

src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php

Lines changed: 302 additions & 52 deletions
Large diffs are not rendered by default.

src/Illuminate/Redis/Connections/PacksPhpRedisValues.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ public function pack(array $values): array
8282
return array_map($processor, $values);
8383
}
8484

85+
/**
86+
* Determine if JSON serialization is enabled.
87+
*
88+
* @return bool
89+
*/
90+
public function usesJsonSerialization(): bool
91+
{
92+
return defined('Redis::SERIALIZER_JSON') &&
93+
$this->client->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_JSON;
94+
}
95+
8596
/**
8697
* Determine if compression is enabled.
8798
*

tests/Cache/RedisCacheIntegrationTest.php

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,66 @@ class RedisCacheIntegrationTest extends TestCase
1111
{
1212
use InteractsWithRedis;
1313

14-
protected function setUp(): void
15-
{
16-
parent::setUp();
17-
$this->setUpRedis();
18-
}
19-
2014
protected function tearDown(): void
2115
{
22-
parent::tearDown();
2316
$this->tearDownRedis();
17+
18+
parent::tearDown();
2419
}
2520

2621
/**
27-
* @dataProvider redisDriverProvider
22+
* @dataProvider extendedRedisConnectionDataProvider
2823
*
29-
* @param string $driver
24+
* @param string $connection
3025
*/
31-
public function testRedisCacheAddTwice($driver)
26+
public function testRedisCacheAddTwice($connection)
3227
{
33-
$store = new RedisStore($this->redis[$driver]);
34-
$repository = new Repository($store);
28+
$repository = $this->getRepository($connection);
29+
3530
$this->assertTrue($repository->add('k', 'v', 3600));
3631
$this->assertFalse($repository->add('k', 'v', 3600));
37-
$this->assertGreaterThan(3500, $this->redis[$driver]->connection()->ttl('k'));
32+
$this->assertGreaterThan(3500, $repository->getStore()->connection()->ttl('k'));
3833
}
3934

4035
/**
4136
* Breaking change.
4237
*
43-
* @dataProvider redisDriverProvider
38+
* @dataProvider extendedRedisConnectionDataProvider
4439
*
45-
* @param string $driver
40+
* @param string $connection
4641
*/
47-
public function testRedisCacheAddFalse($driver)
42+
public function testRedisCacheAddFalse($connection)
4843
{
49-
$store = new RedisStore($this->redis[$driver]);
50-
$repository = new Repository($store);
44+
$repository = $this->getRepository($connection);
45+
5146
$repository->forever('k', false);
5247
$this->assertFalse($repository->add('k', 'v', 60));
53-
$this->assertEquals(-1, $this->redis[$driver]->connection()->ttl('k'));
48+
$this->assertEquals(-1, $repository->getStore()->connection()->ttl('k'));
5449
}
5550

5651
/**
5752
* Breaking change.
5853
*
59-
* @dataProvider redisDriverProvider
54+
* @dataProvider extendedRedisConnectionDataProvider
6055
*
61-
* @param string $driver
56+
* @param string $connection
6257
*/
63-
public function testRedisCacheAddNull($driver)
58+
public function testRedisCacheAddNull($connection)
6459
{
65-
$store = new RedisStore($this->redis[$driver]);
66-
$repository = new Repository($store);
60+
$repository = $this->getRepository($connection);
61+
6762
$repository->forever('k', null);
6863
$this->assertFalse($repository->add('k', 'v', 60));
6964
}
65+
66+
/**
67+
* Builds a cache repository out of a predefined redis connection name.
68+
*
69+
* @param string $connection
70+
* @return \Illuminate\Cache\Repository
71+
*/
72+
private function getRepository($connection)
73+
{
74+
return new Repository(new RedisStore($this->getRedisManager($connection)));
75+
}
7076
}

0 commit comments

Comments
 (0)