Skip to content

Commit

Permalink
[5.4] Don’t require PhpRedis extension for tests (#17910)
Browse files Browse the repository at this point in the history
* Add `disconnect()` alias to `PhpRedisConnection`

* Don’t require `phpredis` extension for tests
  • Loading branch information
tillkruss authored and taylorotwell committed Feb 13, 2017
1 parent be9bc6d commit 1c868e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Redis/Connections/PhpRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public function createSubscription($channels, Closure $callback, $method = 'subs
//
}

/**
* Disconnects from the Redis instance.
*
* @return void
*/
public function disconnect()
{
$this->client->close();
}

/**
* Pass other method calls down to the underlying client.
*
Expand Down
21 changes: 13 additions & 8 deletions tests/Redis/InteractsWithRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function setUpRedis()
return;
}

foreach (['predis', 'phpredis'] as $driver) {
$this->redis[$driver] = new RedisManager($driver, [
foreach ($this->redisDriverProvider() as $driver) {
$this->redis[$driver[0]] = new RedisManager($driver[0], [
'cluster' => false,
'default' => [
'host' => $host,
Expand All @@ -53,18 +53,23 @@ public function setUpRedis()

public function tearDownRedis()
{
if ($this->redis) {
$this->redis['predis']->connection()->flushdb();
$this->redis['predis']->connection()->disconnect();
$this->redis['phpredis']->connection()->close();
$this->redis['predis']->connection()->flushdb();

foreach ($this->redisDriverProvider() as $driver) {
$this->redis[$driver[0]]->connection()->disconnect();
}
}

public function redisDriverProvider()
{
return [
$providers = [
['predis'],
['phpredis'],
];

if (extension_loaded('redis')) {
$providers[] = ['phpredis'];
}

return $providers;
}
}

0 comments on commit 1c868e1

Please sign in to comment.