public function testReturnsPendingAsIteratorTypeObject()
 {
     $t1 = new Transaction(new Client(), new Request('GET', 'http://t.com'));
     $t2 = new Transaction(new Client(), new Request('GET', 'http://t.com'));
     $t3 = new Transaction(new Client(), new Request('GET', 'http://t.com'));
     $iter = new \ArrayIterator([$t1, $t2, $t3]);
     $b = new BatchContext('foo', false, $iter);
     $this->assertTrue($b->hasPending());
     $this->assertSame($t1, $b->nextPending());
     $this->assertTrue($b->hasPending());
     $this->assertSame($t2, $b->nextPending());
     $this->assertTrue($b->hasPending());
     $this->assertSame($t3, $b->nextPending());
     $this->assertFalse($b->hasPending());
     $this->assertNull($b->nextPending());
 }
Exemple #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);
 }
 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));
 }
 private function throwException(RequestException $e, BatchContext $context)
 {
     if ($context->throwsExceptions()) {
         $this->releaseMultiHandle($context->getMultiHandle());
         throw $e;
     }
 }