Exemplo n.º 1
0
 public function testManagesHandles()
 {
     $m = curl_multi_init();
     $b = new BatchContext($m, true);
     $h = curl_init();
     $t = new Transaction(new Client(), new Request('GET', 'http://httbin.org'));
     $b->addTransaction($t, $h);
     $this->assertSame($t, $b->findTransaction($h));
     $b->removeTransaction($t);
     try {
         $this->assertEquals([], $b->findTransaction($h));
         $this->fail('Did not throw');
     } catch (\RuntimeException $e) {
     }
     curl_multi_close($m);
 }
Exemplo n.º 2
0
 public function testCanCloseAll()
 {
     $m = curl_multi_init();
     $b = new BatchContext($m, true);
     $h = curl_init();
     $t = new Transaction(new Client(), new Request('GET', 'http://httbin.org'));
     $b->addTransaction($t, $h);
     $b->removeAll();
     $this->assertFalse($b->isActive());
     $this->assertEquals(0, count($this->readAttribute($b, 'handles')));
     curl_multi_close($m);
 }
Exemplo n.º 3
0
 private function retryFailedConnection(TransactionInterface $transaction, BatchContext $context)
 {
     // Add the request back to the batch to retry automatically.
     $context->addTransaction($transaction, call_user_func($this->curlFactory, $transaction, $this->messageFactory));
 }
Exemplo n.º 4
0
 private function addHandle(TransactionInterface $transaction, BatchContext $context)
 {
     try {
         RequestEvents::emitBefore($transaction);
         // Only transfer if the request was not intercepted
         if (!$transaction->getResponse()) {
             $factory = $this->curlFactory;
             $context->addTransaction($transaction, $factory($transaction, $this->messageFactory));
         }
     } catch (RequestException $e) {
         $this->throwException($e, $context);
     }
 }