Skip to content

Commit

Permalink
Improve test suite related to redis
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
TheLevti committed Feb 4, 2022
1 parent 1c15d08 commit 9f27990
Show file tree
Hide file tree
Showing 14 changed files with 1,421 additions and 1,361 deletions.
352 changes: 303 additions & 49 deletions src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/Illuminate/Redis/Connections/PacksPhpRedisValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public function pack(array $values): array
return array_map($processor, $values);
}

/**
* Determine if JSON serialization is enabled.
*
* @return bool
*/
public function jsonSerialized(): bool
{
return defined('Redis::SERIALIZER_JSON') &&
$this->client->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_JSON;
}

/**
* Determine if compression is enabled.
*
Expand Down
54 changes: 30 additions & 24 deletions tests/Cache/RedisCacheIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,66 @@ class RedisCacheIntegrationTest extends TestCase
{
use InteractsWithRedis;

protected function setUp(): void
{
parent::setUp();
$this->setUpRedis();
}

protected function tearDown(): void
{
parent::tearDown();
$this->tearDownRedis();

parent::tearDown();
}

/**
* @dataProvider redisDriverProvider
* @dataProvider extendedRedisConnectionDataProvider
*
* @param string $driver
* @param string $connection
*/
public function testRedisCacheAddTwice($driver)
public function testRedisCacheAddTwice($connection)
{
$store = new RedisStore($this->redis[$driver]);
$repository = new Repository($store);
$repository = $this->getRepository($connection);

$this->assertTrue($repository->add('k', 'v', 3600));
$this->assertFalse($repository->add('k', 'v', 3600));
$this->assertGreaterThan(3500, $this->redis[$driver]->connection()->ttl('k'));
$this->assertGreaterThan(3500, $repository->getStore()->connection()->ttl('k'));
}

/**
* Breaking change.
*
* @dataProvider redisDriverProvider
* @dataProvider extendedRedisConnectionDataProvider
*
* @param string $driver
* @param string $connection
*/
public function testRedisCacheAddFalse($driver)
public function testRedisCacheAddFalse($connection)
{
$store = new RedisStore($this->redis[$driver]);
$repository = new Repository($store);
$repository = $this->getRepository($connection);

$repository->forever('k', false);
$this->assertFalse($repository->add('k', 'v', 60));
$this->assertEquals(-1, $this->redis[$driver]->connection()->ttl('k'));
$this->assertEquals(-1, $repository->getStore()->connection()->ttl('k'));
}

/**
* Breaking change.
*
* @dataProvider redisDriverProvider
* @dataProvider extendedRedisConnectionDataProvider
*
* @param string $driver
* @param string $connection
*/
public function testRedisCacheAddNull($driver)
public function testRedisCacheAddNull($connection)
{
$store = new RedisStore($this->redis[$driver]);
$repository = new Repository($store);
$repository = $this->getRepository($connection);

$repository->forever('k', null);
$this->assertFalse($repository->add('k', 'v', 60));
}

/**
* Builds a cache repository out of a predefined redis connection name.
*
* @param string $connection
* @return \Illuminate\Cache\Repository
*/
private function getRepository($connection)
{
return new Repository(new RedisStore($this->getRedisManager($connection)));
}
}
Loading

0 comments on commit 9f27990

Please sign in to comment.