From 1c868e1afab726726f8c587bd970a85dd9cf3adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Mon, 13 Feb 2017 13:32:34 -0800 Subject: [PATCH] =?UTF-8?q?[5.4]=20Don=E2=80=99t=20require=20PhpRedis=20ex?= =?UTF-8?q?tension=20for=20tests=20(#17910)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add `disconnect()` alias to `PhpRedisConnection` * Don’t require `phpredis` extension for tests --- .../Redis/Connections/PhpRedisConnection.php | 10 +++++++++ tests/Redis/InteractsWithRedis.php | 21 ++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 301180a385bc..21d80fccfbfd 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -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. * diff --git a/tests/Redis/InteractsWithRedis.php b/tests/Redis/InteractsWithRedis.php index a453ef0f1e7f..d3b6c3307a74 100644 --- a/tests/Redis/InteractsWithRedis.php +++ b/tests/Redis/InteractsWithRedis.php @@ -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, @@ -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; } }