once()->with('auth0_token')->andReturns(null); Http::fake([ '*' => Http::response([ "access_token" => "token", "scope" => "read:client_grants", "expires_in" => 86400, "token_type" => "Bearer" ]) ]); Redis::shouldReceive('set')->with('auth0_token', "token", 'EX', 86400); $tokenService = app(Auth0Service::class); $this->assertEquals("token", $tokenService->getToken()); } public function testIsInCache() { Redis::shouldReceive('get')->once()->with('auth0_token')->andReturns("token"); Redis::shouldReceive('set')->never(); Http::shouldReceive('post')->never(); $tokenService = app(Auth0Service::class); $this->assertEquals("token", $tokenService->getToken()); } }