2012-06-14 09:22:55 -07:00
|
|
|
<?php
|
|
|
|
|
2012-09-05 21:23:40 -07:00
|
|
|
namespace Guzzle\Tests\Batch;
|
2012-06-14 09:22:55 -07:00
|
|
|
|
2012-09-05 21:23:40 -07:00
|
|
|
use Guzzle\Batch\BatchClosureTransfer;
|
2012-06-14 09:22:55 -07:00
|
|
|
|
|
|
|
/**
|
2012-09-05 21:23:40 -07:00
|
|
|
* @covers Guzzle\Batch\BatchClosureTransfer
|
2012-06-14 09:22:55 -07:00
|
|
|
*/
|
|
|
|
class BatchClosureTransferTest extends \Guzzle\Tests\GuzzleTestCase
|
|
|
|
{
|
|
|
|
/**
|
2012-09-05 21:23:40 -07:00
|
|
|
* @var Guzzle\Batch\BatchClosureTransfer The transfer fixture
|
2012-06-14 09:22:55 -07:00
|
|
|
*/
|
|
|
|
protected $transferStrategy;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array|null An array for keeping track of items passed into the transfer closure
|
|
|
|
*/
|
|
|
|
protected $itemsTransferred;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->itemsTransferred = null;
|
|
|
|
$itemsTransferred =& $this->itemsTransferred;
|
|
|
|
|
|
|
|
$this->transferStrategy = new BatchClosureTransfer(function (array $batch) use (&$itemsTransferred) {
|
|
|
|
$itemsTransferred = $batch;
|
|
|
|
return;
|
2012-06-25 10:12:53 -07:00
|
|
|
});
|
2012-06-14 09:22:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testTransfersBatch()
|
|
|
|
{
|
|
|
|
$batchedItems = array('foo', 'bar', 'baz');
|
|
|
|
$this->transferStrategy->transfer($batchedItems);
|
|
|
|
|
|
|
|
$this->assertEquals($batchedItems, $this->itemsTransferred);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTransferBailsOnEmptyBatch()
|
|
|
|
{
|
|
|
|
$batchedItems = array();
|
|
|
|
$this->transferStrategy->transfer($batchedItems);
|
|
|
|
|
|
|
|
$this->assertNull($this->itemsTransferred);
|
|
|
|
}
|
2012-06-25 10:12:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Guzzle\Common\Exception\InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testEnsuresCallableIsCallable()
|
|
|
|
{
|
|
|
|
$foo = new BatchClosureTransfer('uh oh!');
|
|
|
|
}
|
2012-06-14 09:22:55 -07:00
|
|
|
}
|