public function testCanGetSeveralRandomValue() { $array = Arrays::random($this->arrayNumbers, 2); foreach ($array as $a) { $this->assertContains($a, $this->arrayNumbers); } }
/** * @param $host * @param int $maxRecursion * @return Observable\AnonymousObservable with ip address */ public function resolve($host, $maxRecursion = 50) { // Don't resolve IP if (filter_var($host, FILTER_VALIDATE_IP)) { return Observable::just($host); } // Caching if (array_key_exists($host, $this->cache)) { return Observable::just($this->cache[$host]); } return $this->lookup($host, 'A')->flatMap(function (Event $event) use($host, $maxRecursion) { $ip = Arrays::random($event->data["answers"]); if (!$ip) { throw new RemoteNotFoundException("Can't resolve {$host}"); } if (!filter_var($ip, FILTER_VALIDATE_IP)) { if ($maxRecursion <= 0) { throw new RecursionLimitException(); } return $this->resolve($ip, $maxRecursion - 1); } $this->cache[$host] = $ip; return Observable::just($ip); }); }