Skip to content

Commit

Permalink
[6.x] Fixed code that depended on getenv (#30924)
Browse files Browse the repository at this point in the history
* Fixed code that depended on getenv

* Update InteractsWithRedis.php

* Apply fixes from StyleCI (#30925)
  • Loading branch information
GrahamCampbell authored and taylorotwell committed Dec 25, 2019
1 parent 2bde5b7 commit a7db749
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Illuminate\Foundation\Application;
use Illuminate\Redis\RedisManager;
use Illuminate\Support\Env;

trait InteractsWithRedis
{
Expand All @@ -30,8 +31,8 @@ trait InteractsWithRedis
public function setUpRedis()
{
$app = $this->app ?? new Application;
$host = getenv('REDIS_HOST') ?: '127.0.0.1';
$port = getenv('REDIS_PORT') ?: 6379;
$host = Env::get('REDIS_HOST', '127.0.0.1');
$port = Env::get('REDIS_PORT', 6379);

if (! extension_loaded('redis')) {
$this->markTestSkipped('The redis extension is not installed. Please install the extension to enable '.__CLASS__);
Expand Down Expand Up @@ -63,7 +64,7 @@ public function setUpRedis()
try {
$this->redis['phpredis']->connection()->flushdb();
} catch (Exception $e) {
if ($host === '127.0.0.1' && $port === 6379 && getenv('REDIS_HOST') === false) {
if ($host === '127.0.0.1' && $port === 6379 && Env::get('REDIS_HOST') === null) {
static::$connectionFailedOnceWithDefaultsSkip = true;
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Redis/RedisConnectionTest.php
Expand Up @@ -554,8 +554,8 @@ public function connections()
'phpredis' => $this->redis['phpredis']->connection(),
];

$host = getenv('REDIS_HOST') ?: '127.0.0.1';
$port = getenv('REDIS_PORT') ?: 6379;
$host = env('REDIS_HOST', '127.0.0.1');
$port = env('REDIS_PORT', 6379);

$prefixedPhpredis = new RedisManager(new Application, 'phpredis', [
'cluster' => false,
Expand Down

0 comments on commit a7db749

Please sign in to comment.