1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\ExceptionBufferingBatch;
use Guzzle\Batch\Batch;
use Guzzle\Batch\BatchSizeDivisor;
class ExceptionBufferingBatchTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testFlushesEntireBatchWhileBufferingErroredBatches()
{
$t = $this->getMockBuilder('Guzzle\Batch\BatchTransferInterface')
->setMethods(array('transfer'))
->getMock();
$d = new BatchSizeDivisor(1);
$batch = new Batch($t, $d);
$called = 0;
$t->expects($this->exactly(3))
->method('transfer')
->will($this->returnCallback(function ($batch) use (&$called) {
if (++$called === 2) {
throw new \Exception('Foo');
}
}));
$decorator = new ExceptionBufferingBatch($batch);
$decorator->add('foo')->add('baz')->add('bar');
$result = $decorator->flush();
$e = $decorator->getExceptions();
$this->assertEquals(1, count($e));
$this->assertEquals(array('baz'), $e[0]->getBatch());
$decorator->clearExceptions();
$this->assertEquals(0, count($decorator->getExceptions()));
$this->assertEquals(array('foo', 'bar'), $result);
}
}