/** * @depends test_construct * @depends test_parse * @dataProvider generateValidURIs * @covers ::offsetExists */ public function test_offsetExists($Input) { # Valid arguments foreach ($this->generateValidURIs() as $Arguments) { list($Input) = $Arguments; $URI = $this->getMockForAbstractClass('\\BLW\\Type\\AURI', array($Input)); foreach ($this->URI->parse($Input) as $k => $v) { $this->assertTrue($URI->offsetExists($k), sprintf('IURI[%s] should exist', $k)); } } # Invalid arguments $this->assertFalse(isset($URI['undefined']), 'IURI[undefined] should not exist'); }
/** * Perform a request and update $FreeHandles. * * @link http://www.php.net/manual/en/function.curl-setopt-array.php curl_setopt_array() * @link http://www.php.net/manual/en/function.curl-setopt.php curl_multi_add_handle() * * @throws \RuntimeException If there is a cURL error. * @throws \BLW\Model\InvalidArgumentException If <code>$Handle</code> is not a valid resource. * * @param resource $Handle * Resource from <code>curl_init()</code> stored in <code>$Handles</code>. * @param array $Options * Options passed to <code>curl_setopt_array()</code> * @return boolean <code>TRUE</code> on success. <code>FALSE</code> otherwise. */ public function execute($Handle, array $Options) { // Validate $Handle if (!is_resource($Handle) ?: !in_array($Handle, $this->FreeHandles)) { throw new InvalidArgumentException(0); } elseif (!($result = @curl_setopt_array($Handle, $Options))) { throw new RuntimeException('Unable to set cURL options', curl_errno($Handle)); } // Add handle $result = curl_multi_add_handle($this->MainHandle, $Handle); // Check results if ($result == 0) { // Remove handle from free list $this->FreeHandles = array_filter($this->FreeHandles, function ($v) use($Handle) { return $v != $Handle; }); // Update Stats // 1. NewConnections $this->Stats['NewConnections'][] = new DateTime(); // 2. HostConnections if (isset($Options[CURLOPT_URL])) { $Host = AURI::parse($Options[CURLOPT_URL]); $Host = $Host['host']; // Stats exist? Update if (isset($this->Stats['HostConnections'][$Host])) { $this->Stats['HostConnections'][$Host][] = $Handle; // No stats? Create } else { $this->Stats['HostConnections'][$Host] = array($Handle); } } // Done return true; // @codeCoverageIgnoreStart // Unable to add } else { // Exception throw new RuntimeException(sprintf('Error [%d]: Unable to add curl request (%s)', $result, curl_error($Handle)), $result); } // @codeCoverageIgnoreEnd }