I have a block of code in my Laravel 5 project which uses the Redis facade which I'd like to test. The code is part of a trait and structure is basically
private function getAgentArray(): ?array
{
try {
$key = Request::agentId();
return Redis::exists($key) ? json_decode(Redis::get($key), true) : null;
} catch (\Exception $e) {
Log::debug($e->getMessage());
return null;
}
}
The function should provide an array of data for use internally in any classes which use the trait.
Is there a way I can mock this so that its output would be available for the class using the trait?. Basically I'm looking for getAgentArray()
to return a fake array when called. I can't mock this directly as it's private so needs to be through the Redis facade if that's possible.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire