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: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84:
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchCommandTransfer;
use Guzzle\Service\Client;
use Guzzle\Tests\Service\Mock\Command\MockCommand as Mc;
class BatchCommandTransferTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testCreatesBatchesBasedOnClient()
{
$client1 = new Client('http://www.example.com');
$client2 = new Client('http://www.example.com');
$commands = array(new Mc(), new Mc(), new Mc(), new Mc(), new Mc());
$queue = new \SplQueue();
foreach ($commands as $i => $command) {
if ($i % 2) {
$command->setClient($client1);
} else {
$command->setClient($client2);
}
$queue[] = $command;
}
$batch = new BatchCommandTransfer(2);
$this->assertEquals(array(
array($commands[0], $commands[2]),
array($commands[4]),
array($commands[1], $commands[3])
), $batch->createBatches($queue));
}
public function testEnsuresAllItemsAreCommands()
{
$queue = new \SplQueue();
$queue[] = 'foo';
$batch = new BatchCommandTransfer(2);
$batch->createBatches($queue);
}
public function testTransfersBatches()
{
$client = $this->getMockBuilder('Guzzle\Service\Client')
->setMethods(array('send'))
->getMock();
$client->expects($this->once())
->method('send');
$command = new Mc();
$command->setClient($client);
$batch = new BatchCommandTransfer(2);
$batch->transfer(array($command));
}
public function testDoesNotTransfersEmptyBatches()
{
$batch = new BatchCommandTransfer(2);
$batch->transfer(array());
}
public function testEnsuresAllCommandsUseTheSameClient()
{
$batch = new BatchCommandTransfer(2);
$client1 = new Client('http://www.example.com');
$client2 = new Client('http://www.example.com');
$command1 = new Mc();
$command1->setClient($client1);
$command2 = new Mc();
$command2->setClient($client2);
$batch->transfer(array($command1, $command2));
}
}