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