From b63dcc8d0ff2d7222c0aa5742535a4fe86fc6617 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Tue, 23 Oct 2018 12:17:31 +0300 Subject: [PATCH] fix redis tests --- .travis.yml | 1 + pkg/redis/PRedis.php | 4 ++++ pkg/redis/PhpRedis.php | 4 ++++ pkg/redis/RedisConnectionFactory.php | 8 -------- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8eddd23c3..f358a00cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ cache: before_install: - echo "extension = mongodb.so" >> $HOME/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - echo "extension = redis.so" >> $HOME/.phpenv/versions/$(phpenv version-name)/etc/php.ini install: - rm $HOME/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini; diff --git a/pkg/redis/PRedis.php b/pkg/redis/PRedis.php index 1c541df65..a6a44e11f 100644 --- a/pkg/redis/PRedis.php +++ b/pkg/redis/PRedis.php @@ -30,6 +30,10 @@ class PRedis implements Redis */ public function __construct(array $config) { + if (false == class_exists(Client::class)) { + throw new \LogicException('The package "predis/predis" must be installed. Please run "composer req predis/predis:^1.1" to install it'); + } + $this->options = $config['predis_options']; $this->parameters = [ diff --git a/pkg/redis/PhpRedis.php b/pkg/redis/PhpRedis.php index 68652e6b6..bf6da281a 100644 --- a/pkg/redis/PhpRedis.php +++ b/pkg/redis/PhpRedis.php @@ -19,6 +19,10 @@ class PhpRedis implements Redis */ public function __construct(array $config) { + if (false == class_exists(\Redis::class)) { + throw new \LogicException('You must install the redis extension to use phpredis'); + } + $this->config = $config; } diff --git a/pkg/redis/RedisConnectionFactory.php b/pkg/redis/RedisConnectionFactory.php index 0a5bb80a7..5d5ec3b40 100644 --- a/pkg/redis/RedisConnectionFactory.php +++ b/pkg/redis/RedisConnectionFactory.php @@ -95,16 +95,8 @@ private function createRedis(): Redis { if (false == $this->redis) { if (in_array('phpredis', $this->config['scheme_extensions'], true)) { - if (false == class_exists(\Redis::class)) { - throw new \LogicException('You must install the redis extension to use phpredis'); - } - $this->redis = new PhpRedis($this->config); } else { - if (false == class_exists(\Predis\Client::class)) { - throw new \LogicException('The package "predis/predis" must be installed. Please run "composer req predis/predis:^1.1" to install it'); - } - $this->redis = new PRedis($this->config); }