コード例 #1
0
ファイル: BatchContext.php プロジェクト: puzzlehttp/puzzle
 /**
  * Remove a transaction and associated handle from the context
  *
  * @param puzzle_adapter_TransactionInterface $transaction Transaction to remove
  *
  * @return array Returns the curl_getinfo array
  * @throws puzzle_exception_AdapterException if the transaction is not found
  */
 public function removeTransaction(puzzle_adapter_TransactionInterface $transaction)
 {
     if (!$this->handles->contains($transaction)) {
         throw new puzzle_exception_AdapterException('Transaction not registered');
     }
     $handle = $this->handles->offsetGet($transaction);
     $this->handles->detach($transaction);
     $info = curl_getinfo($handle);
     $code = curl_multi_remove_handle($this->multi, $handle);
     curl_close($handle);
     if ($code !== CURLM_OK) {
         puzzle_adapter_curl_MultiAdapter::throwMultiError($code);
     }
     return $info;
 }
コード例 #2
0
 public function testThrowsImmediatelyWhenInstructed()
 {
     puzzle_test_Server::flush();
     puzzle_test_Server::enqueue(array("HTTP/1.1 501\r\nContent-Length: 0\r\n\r\n"));
     $c = new puzzle_Client(array('base_url' => puzzle_test_Server::$url));
     $request = $c->createRequest('GET', '/');
     $request->getEmitter()->on('error', array($this, '__callback_testThrowsImmediatelyWhenInstructed'));
     $transactions = array(new puzzle_adapter_Transaction($c, $request));
     $a = new puzzle_adapter_curl_MultiAdapter(new puzzle_message_MessageFactory());
     try {
         $a->sendAll(new ArrayIterator($transactions), 1);
         $this->fail('Did not throw');
     } catch (puzzle_exception_RequestException $e) {
         $this->assertSame($request, $e->getRequest());
     }
 }