Exemple #1
0
 /**
  * @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());
     }
 }
Exemple #2
0
 /**
  * Start a Request.
  *
  * @ignore
  * @param \BLW\Type\HTTP\IRequest $Request
  * @param resource $Handle
  */
 private function _start(IRequest $Request, $Handle)
 {
     // Validate $Request and $Handle
     if ($this->contains($Request)) {
         if (($Response = $this[$Request]) instanceof IResponse && is_resource($Handle)) {
             // Execute request
             try {
                 $this->_Helper->execute($Handle, $this->translate($Request));
                 // Store handle
                 $Response['handle'] = $Handle;
                 // Update running flag
                 $Response['Running'] = true;
                 $Response['Finished'] = false;
                 // Forward exceptions
             } catch (RuntimeException $e) {
                 // @codeCoverageIgnoreStart
                 throw new RuntimeException($e->getMessage(), $e->getCode());
                 // @codeCoverageIgnoreEnd
             }
         }
     }
 }