Call to a member function connect() on null
mikehuboo opened this issue · comments
I'm developing a package that uses Redis.
when I add the following
<env name="REDIS_CLIENT" value="mock"/>
to phpunit.xml I get the following error:
Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function connect() on null
/var/www/html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php:109
/var/www/html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php:90
/var/www/html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php:263
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261
package dependencies are as follows:
"require": {
"php": "^7.2",
"guzzlehttp/guzzle": "^6.5|^7.0.1",
"predis/predis": "^1.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"josiasmontag/laravel-redis-mock": "^1.3",
"orchestra/testbench": "~3.8.6 || ^4.8 || ^5.2 || ^6.0",
"phpunit/phpunit": "^7.5"
},
In my class triggering the errror i am doing the following:
use Illuminate\Support\Facades\Redis as RedisCache;
/**
* @var RedisCache
*/
public $redisCache;
public function __construct()
{
$this->redisCache = new RedisCache();
}
/**
* @param string $key
*
* @throws Exception
*
* @return array|null
*/
public function get(string $key): ?array
{
$contents = $this->redisCache::get($key);
if (!$contents) {
return null;
}
return json_decode($contents, true);
}
can i get some advice on best way to implement package?
I had the same issue and I had to make sure that for my test suite the Lunaweb\RedisMock\Providers\RedisMockServiceProvider
was getting loaded in. Otherwise laravel didn't have the custom connector setup to pair the mock
client
@matthewdevine thanks. That did the trick.