/** * Does grunt work of finishing a request. * * @ignore * @param \BLW\Type\HTTP\IRequest $Request */ private function _finish(IRequest $Request) { // Validate $Request if ($this->contains($Request)) { if (($Response = $this[$Request]) instanceof IResponse) { $Handle = $Response['handle']; // Create Response // Is code known? if ($Response->isValidCode(intval(curl_getinfo($Handle, CURLINFO_HTTP_CODE)))) { // parse response $Response = Response::createFromString(curl_multi_getcontent($Handle)); // Update handle $Response['handle'] = $Handle; // RequestURI $Response->setRequestURI($Request->getURI()); // Update $this[$Request] = $Response; } // Update finished flag $Response['Running'] = false; $Response['Finished'] = true; // Update info $this->_update($Request); // Free Handle $this->_Helper->freeHandle($Handle); // Does mediator exist? if ($this->_Mediator instanceof IMediator) { // Request.Finished event $this->_do('Request.Finished', new Event($this, array('Request' => &$Request, 'Response' => &$Response))); } } } }
/** * @depends test_getFreeHandle * @depends test_freeHandle * @covers ::execute */ public function test_execute() { $Handle1 = $this->Helper->FreeHandles[0]; $Handle2 = $this->Helper->FreeHandles[1]; $this->Helper->execute($Handle1, array(CURLOPT_URL => 'http://example.com', CURLOPT_RETURNTRANSFER => 1)); $this->Helper->execute($Handle2, array(CURLOPT_URL => 'http://example.com', CURLOPT_RETURNTRANSFER => 1)); $active = true; do { $result = (int) curl_multi_exec($this->Helper->MainHandle, $active); } while ($result == CURLM_CALL_MULTI_PERFORM || $active); $this->assertContains('<!doctype', strval(curl_multi_getcontent($Handle1)), 'Helper::execute() Failed to execute cURL operation'); $this->assertContains('<!doctype', strval(curl_multi_getcontent($Handle2)), 'Helper::execute() Failed to execute cURL operation'); $this->assertCount(2, $this->Helper->Stats['NewConnections'], 'Helper::execute() Failed to register new connections'); $this->assertCount(2, $this->Helper->Stats['HostConnections']['example.com'], 'Helper::execute() Failed to register new connextions'); # Invalid curl handle try { $this->Helper->execute(null, array()); $this->fail('Failed to generate exeption with invalid arguments'); } catch (InvalidArgumentException $e) { } # Invalid cURL options try { $this->Helper->execute($this->Helper->FreeHandles[3], array('foo' => 1)); $this->fail('Failed to generate exception with invalid cURL options'); } catch (\RuntimeException $e) { $this->assertContains('Unable to set', $e->getMessage(), 'Invalid notice: ' . $e->getMessage()); } }