Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Improve redis test suite #40816

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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