13 private function getMockTransfer()
15 return $this->getMock(
'Guzzle\Batch\BatchTransferInterface');
18 private function getMockDivisor()
20 return $this->getMock(
'Guzzle\Batch\BatchDivisorInterface');
25 $batch =
new Batch($this->getMockTransfer(), $this->getMockDivisor());
26 $this->assertSame($batch, $batch->add(
'foo'));
27 $this->assertEquals(1, count($batch));
32 $transfer = $this->getMockTransfer();
33 $transfer->expects($this->exactly(2))
36 $divisor = $this->getMockDivisor();
37 $divisor->expects($this->once())
38 ->method(
'createBatches')
39 ->will($this->returnValue(array(array(
'foo',
'baz'), array(
'bar'))));
41 $batch =
new Batch($transfer, $divisor);
43 $batch->add(
'foo')->add(
'baz')->add(
'bar');
44 $items = $batch->flush();
46 $this->assertEquals(array(
'foo',
'baz',
'bar'), $items);
52 $originalException = new \Exception(
'Foo!');
54 $transfer = $this->getMockTransfer();
55 $transfer->expects($this->exactly(2))
57 ->will($this->returnCallback(
function () use (&$called, $originalException) {
59 throw $originalException;
63 $divisor = $this->getMockDivisor();
64 $batch =
new Batch($transfer, $divisor);
68 $queue = $this->readAttribute($batch,
'queue');
70 $divisor->expects($this->once())
71 ->method(
'createBatches')
72 ->will($this->returnCallback(
function ($batch) use ($queue) {
73 foreach ($queue as $item) {
76 return array_chunk($items, 2);
79 $batch->add(
'foo')->add(
'baz')->add(
'bar')->add(
'bee')->add(
'boo');
80 $this->assertFalse($batch->isEmpty());
83 $items = $batch->flush();
84 $this->fail(
'Expected exception');
86 $this->assertEquals($originalException, $e->getPrevious());
87 $this->assertEquals(array(
'bar',
'bee'), array_values($e->
getBatch()));
88 $this->assertEquals(1, count($batch));