3
namespace GuzzleHttp\Tests\Adapter\Curl;
5
use GuzzleHttp\Adapter\Curl\BatchContext;
6
use GuzzleHttp\Adapter\Transaction;
8
use GuzzleHttp\Message\Request;
11
* @covers GuzzleHttp\Adapter\Curl\BatchContext
13
class BatchContextTest extends \PHPUnit_Framework_TestCase
15
public function testProvidesGetters()
17
$m = curl_multi_init();
18
$b = new BatchContext($m, true);
19
$this->assertTrue($b->throwsExceptions());
20
$this->assertSame($m, $b->getMultiHandle());
21
$this->assertFalse($b->hasPending());
25
public function testValidatesTransactionsAreNotAddedTwice()
27
$m = curl_multi_init();
28
$b = new BatchContext($m, true);
32
new Request('GET', 'http://httbin.org')
34
$b->addTransaction($t, $h);
36
$b->addTransaction($t, $h);
37
$this->fail('Did not throw');
38
} catch (\RuntimeException $e) {
44
public function testManagesHandles()
46
$m = curl_multi_init();
47
$b = new BatchContext($m, true);
51
new Request('GET', 'http://httbin.org')
53
$b->addTransaction($t, $h);
54
$this->assertTrue($b->isActive());
55
$this->assertSame($t, $b->findTransaction($h));
56
$b->removeTransaction($t);
57
$this->assertFalse($b->isActive());
59
$this->assertEquals([], $b->findTransaction($h));
60
$this->fail('Did not throw');
61
} catch (\RuntimeException $e) {}
66
* @expectedException \RuntimeException
67
* @expectedExceptionMessage Transaction not registered
69
public function testThrowsWhenRemovingNonExistentTransaction()
71
$b = new BatchContext('foo', false);
74
new Request('GET', 'http://httbin.org')
76
$b->removeTransaction($t);
79
public function testReturnsPendingAsIteratorTypeObject()
81
$t1 = new Transaction(new Client(), new Request('GET', 'http://t.com'));
82
$t2 = new Transaction(new Client(), new Request('GET', 'http://t.com'));
83
$t3 = new Transaction(new Client(), new Request('GET', 'http://t.com'));
84
$iter = new \ArrayIterator([$t1, $t2, $t3]);
85
$b = new BatchContext('foo', false, $iter);
86
$this->assertTrue($b->hasPending());
87
$this->assertSame($t1, $b->nextPending());
88
$this->assertTrue($b->hasPending());
89
$this->assertSame($t2, $b->nextPending());
90
$this->assertTrue($b->hasPending());
91
$this->assertSame($t3, $b->nextPending());
92
$this->assertFalse($b->hasPending());
93
$this->assertNull($b->nextPending());
96
public function testCanCloseAll()
98
$m = curl_multi_init();
99
$b = new BatchContext($m, true);
101
$t = new Transaction(
103
new Request('GET', 'http://httbin.org')
105
$b->addTransaction($t, $h);
107
$this->assertFalse($b->isActive());
108
$this->assertEquals(0, count($this->readAttribute($b, 'handles')));
109
curl_multi_close($m);