init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)

这个提交包含在:
Developer
2026-10-30 10:18:50 +08:00
当前提交 1f3e0ce2f6
共有 9291 个文件被更改,包括 1776674 次插入 和 0 次删除

查看文件

@@ -0,0 +1,33 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\Batch;
/**
* @covers Guzzle\Batch\AbstractBatchDecorator
*/
class AbstractBatchDecoratorTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testProxiesToWrappedObject()
{
$batch = new Batch(
$this->getMock('Guzzle\Batch\BatchTransferInterface'),
$this->getMock('Guzzle\Batch\BatchDivisorInterface')
);
$decoratorA = $this->getMockBuilder('Guzzle\Batch\AbstractBatchDecorator')
->setConstructorArgs(array($batch))
->getMockForAbstractClass();
$decoratorB = $this->getMockBuilder('Guzzle\Batch\AbstractBatchDecorator')
->setConstructorArgs(array($decoratorA))
->getMockForAbstractClass();
$decoratorA->add('foo');
$this->assertFalse($decoratorB->isEmpty());
$this->assertFalse($batch->isEmpty());
$this->assertEquals(array($decoratorB, $decoratorA), $decoratorB->getDecorators());
$this->assertEquals(array(), $decoratorB->flush());
}
}

查看文件

@@ -0,0 +1,86 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchBuilder;
/**
* @covers Guzzle\Batch\BatchBuilder
*/
class BatchBuilderTest extends \Guzzle\Tests\GuzzleTestCase
{
private function getMockTransfer()
{
return $this->getMock('Guzzle\Batch\BatchTransferInterface');
}
private function getMockDivisor()
{
return $this->getMock('Guzzle\Batch\BatchDivisorInterface');
}
private function getMockBatchBuilder()
{
return BatchBuilder::factory()
->transferWith($this->getMockTransfer())
->createBatchesWith($this->getMockDivisor());
}
public function testFactoryCreatesInstance()
{
$builder = BatchBuilder::factory();
$this->assertInstanceOf('Guzzle\Batch\BatchBuilder', $builder);
}
public function testAddsAutoFlush()
{
$batch = $this->getMockBatchBuilder()->autoFlushAt(10)->build();
$this->assertInstanceOf('Guzzle\Batch\FlushingBatch', $batch);
}
public function testAddsExceptionBuffering()
{
$batch = $this->getMockBatchBuilder()->bufferExceptions()->build();
$this->assertInstanceOf('Guzzle\Batch\ExceptionBufferingBatch', $batch);
}
public function testAddHistory()
{
$batch = $this->getMockBatchBuilder()->keepHistory()->build();
$this->assertInstanceOf('Guzzle\Batch\HistoryBatch', $batch);
}
public function testAddsNotify()
{
$batch = $this->getMockBatchBuilder()->notify(function() {})->build();
$this->assertInstanceOf('Guzzle\Batch\NotifyingBatch', $batch);
}
/**
* @expectedException Guzzle\Common\Exception\RuntimeException
*/
public function testTransferStrategyMustBeSet()
{
$batch = BatchBuilder::factory()->createBatchesWith($this->getMockDivisor())->build();
}
/**
* @expectedException Guzzle\Common\Exception\RuntimeException
*/
public function testDivisorStrategyMustBeSet()
{
$batch = BatchBuilder::factory()->transferWith($this->getMockTransfer())->build();
}
public function testTransfersRequests()
{
$batch = BatchBuilder::factory()->transferRequests(10)->build();
$this->assertInstanceOf('Guzzle\Batch\BatchRequestTransfer', $this->readAttribute($batch, 'transferStrategy'));
}
public function testTransfersCommands()
{
$batch = BatchBuilder::factory()->transferCommands(10)->build();
$this->assertInstanceOf('Guzzle\Batch\BatchCommandTransfer', $this->readAttribute($batch, 'transferStrategy'));
}
}

查看文件

@@ -0,0 +1,36 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchClosureDivisor;
/**
* @covers Guzzle\Batch\BatchClosureDivisor
*/
class BatchClosureDivisorTest extends \Guzzle\Tests\GuzzleTestCase
{
/**
* @expectedException Guzzle\Common\Exception\InvalidArgumentException
*/
public function testEnsuresCallableIsCallable()
{
$d = new BatchClosureDivisor(new \stdClass());
}
public function testDividesBatch()
{
$queue = new \SplQueue();
$queue[] = 'foo';
$queue[] = 'baz';
$d = new BatchClosureDivisor(function (\SplQueue $queue, $context) {
return array(
array('foo'),
array('baz')
);
}, 'Bar!');
$batches = $d->createBatches($queue);
$this->assertEquals(array(array('foo'), array('baz')), $batches);
}
}

查看文件

@@ -0,0 +1,52 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchClosureTransfer;
/**
* @covers Guzzle\Batch\BatchClosureTransfer
*/
class BatchClosureTransferTest extends \Guzzle\Tests\GuzzleTestCase
{
/** @var \Guzzle\Batch\BatchClosureTransfer The transfer fixture */
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;
});
}
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);
}
/**
* @expectedException Guzzle\Common\Exception\InvalidArgumentException
*/
public function testEnsuresCallableIsCallable()
{
$foo = new BatchClosureTransfer('uh oh!');
}
}

查看文件

@@ -0,0 +1,83 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchCommandTransfer;
use Guzzle\Service\Client;
use Guzzle\Tests\Service\Mock\Command\MockCommand as Mc;
/**
* @covers Guzzle\Batch\BatchCommandTransfer
*/
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));
}
/**
* @expectedException Guzzle\Common\Exception\InvalidArgumentException
*/
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());
}
/**
* @expectedException Guzzle\Service\Exception\InconsistentClientTransferException
*/
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));
}
}

查看文件

@@ -0,0 +1,80 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchRequestTransfer;
use Guzzle\Http\Client;
use Guzzle\Http\Curl\CurlMulti;
/**
* @covers Guzzle\Batch\BatchRequestTransfer
*/
class BatchRequestTransferTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testCreatesBatchesBasedOnCurlMultiHandles()
{
$client1 = new Client('http://www.example.com');
$client1->setCurlMulti(new CurlMulti());
$client2 = new Client('http://www.example.com');
$client2->setCurlMulti(new CurlMulti());
$request1 = $client1->get();
$request2 = $client2->get();
$request3 = $client1->get();
$request4 = $client2->get();
$request5 = $client1->get();
$queue = new \SplQueue();
$queue[] = $request1;
$queue[] = $request2;
$queue[] = $request3;
$queue[] = $request4;
$queue[] = $request5;
$batch = new BatchRequestTransfer(2);
$this->assertEquals(array(
array($request1, $request3),
array($request3),
array($request2, $request4)
), $batch->createBatches($queue));
}
/**
* @expectedException \Guzzle\Common\Exception\InvalidArgumentException
*/
public function testEnsuresAllItemsAreRequests()
{
$queue = new \SplQueue();
$queue[] = 'foo';
$batch = new BatchRequestTransfer(2);
$batch->createBatches($queue);
}
public function testTransfersBatches()
{
$client = new Client('http://localhost:123');
$request = $client->get();
// For some reason... PHP unit clones the request, which emits a request.clone event. This causes the
// 'sorted' property of the event dispatcher to contain an array in the cloned request that is not present in
// the original.
$request->dispatch('request.clone');
$multi = $this->getMock('Guzzle\Http\Curl\CurlMultiInterface');
$client->setCurlMulti($multi);
$multi->expects($this->once())
->method('add')
->with($request);
$multi->expects($this->once())
->method('send');
$batch = new BatchRequestTransfer(2);
$batch->transfer(array($request));
}
public function testDoesNotTransfersEmptyBatches()
{
$batch = new BatchRequestTransfer(2);
$batch->transfer(array());
}
}

查看文件

@@ -0,0 +1,24 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\BatchSizeDivisor;
/**
* @covers Guzzle\Batch\BatchSizeDivisor
*/
class BatchSizeDivisorTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testDividesBatch()
{
$queue = new \SplQueue();
$queue[] = 'foo';
$queue[] = 'baz';
$queue[] = 'bar';
$d = new BatchSizeDivisor(3);
$this->assertEquals(3, $d->getSize());
$d->setSize(2);
$batches = $d->createBatches($queue);
$this->assertEquals(array(array('foo', 'baz'), array('bar')), $batches);
}
}

查看文件

@@ -0,0 +1,91 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\Batch;
use Guzzle\Batch\Exception\BatchTransferException;
/**
* @covers Guzzle\Batch\Batch
*/
class BatchTest extends \Guzzle\Tests\GuzzleTestCase
{
private function getMockTransfer()
{
return $this->getMock('Guzzle\Batch\BatchTransferInterface');
}
private function getMockDivisor()
{
return $this->getMock('Guzzle\Batch\BatchDivisorInterface');
}
public function testAddsItemsToQueue()
{
$batch = new Batch($this->getMockTransfer(), $this->getMockDivisor());
$this->assertSame($batch, $batch->add('foo'));
$this->assertEquals(1, count($batch));
}
public function testFlushReturnsItems()
{
$transfer = $this->getMockTransfer();
$transfer->expects($this->exactly(2))
->method('transfer');
$divisor = $this->getMockDivisor();
$divisor->expects($this->once())
->method('createBatches')
->will($this->returnValue(array(array('foo', 'baz'), array('bar'))));
$batch = new Batch($transfer, $divisor);
$batch->add('foo')->add('baz')->add('bar');
$items = $batch->flush();
$this->assertEquals(array('foo', 'baz', 'bar'), $items);
}
public function testThrowsExceptionContainingTheFailedBatch()
{
$called = 0;
$originalException = new \Exception('Foo!');
$transfer = $this->getMockTransfer();
$transfer->expects($this->exactly(2))
->method('transfer')
->will($this->returnCallback(function () use (&$called, $originalException) {
if (++$called == 2) {
throw $originalException;
}
}));
$divisor = $this->getMockDivisor();
$batch = new Batch($transfer, $divisor);
// PHPunit clones objects before passing them to a callback.
// Horrible hack to get around this!
$queue = $this->readAttribute($batch, 'queue');
$divisor->expects($this->once())
->method('createBatches')
->will($this->returnCallback(function ($batch) use ($queue) {
foreach ($queue as $item) {
$items[] = $item;
}
return array_chunk($items, 2);
}));
$batch->add('foo')->add('baz')->add('bar')->add('bee')->add('boo');
$this->assertFalse($batch->isEmpty());
try {
$items = $batch->flush();
$this->fail('Expected exception');
} catch (BatchTransferException $e) {
$this->assertEquals($originalException, $e->getPrevious());
$this->assertEquals(array('bar', 'bee'), array_values($e->getBatch()));
$this->assertEquals(1, count($batch));
}
}
}

查看文件

@@ -0,0 +1,45 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\ExceptionBufferingBatch;
use Guzzle\Batch\Batch;
use Guzzle\Batch\BatchSizeDivisor;
/**
* @covers Guzzle\Batch\ExceptionBufferingBatch
*/
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);
}
}

查看文件

@@ -0,0 +1,40 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\FlushingBatch;
use Guzzle\Batch\Batch;
/**
* @covers Guzzle\Batch\FlushingBatch
*/
class FlushingBatchTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testFlushesWhenSizeMeetsThreshold()
{
$t = $this->getMock('Guzzle\Batch\BatchTransferInterface', array('transfer'));
$d = $this->getMock('Guzzle\Batch\BatchDivisorInterface', array('createBatches'));
$batch = new Batch($t, $d);
$queue = $this->readAttribute($batch, 'queue');
$d->expects($this->exactly(2))
->method('createBatches')
->will($this->returnCallback(function () use ($queue) {
$items = array();
foreach ($queue as $item) {
$items[] = $item;
}
return array($items);
}));
$t->expects($this->exactly(2))
->method('transfer');
$flush = new FlushingBatch($batch, 3);
$this->assertEquals(3, $flush->getThreshold());
$flush->setThreshold(2);
$flush->add('foo')->add('baz')->add('bar')->add('bee')->add('boo');
$this->assertEquals(1, count($flush));
}
}

查看文件

@@ -0,0 +1,26 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\HistoryBatch;
use Guzzle\Batch\Batch;
/**
* @covers Guzzle\Batch\HistoryBatch
*/
class HistoryBatchTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testMaintainsHistoryOfItemsAddedToBatch()
{
$batch = new Batch(
$this->getMock('Guzzle\Batch\BatchTransferInterface'),
$this->getMock('Guzzle\Batch\BatchDivisorInterface')
);
$history = new HistoryBatch($batch);
$history->add('foo')->add('baz');
$this->assertEquals(array('foo', 'baz'), $history->getHistory());
$history->clearHistory();
$this->assertEquals(array(), $history->getHistory());
}
}

查看文件

@@ -0,0 +1,45 @@
<?php
namespace Guzzle\Tests\Batch;
use Guzzle\Batch\NotifyingBatch;
use Guzzle\Batch\Batch;
/**
* @covers Guzzle\Batch\NotifyingBatch
*/
class NotifyingBatchTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testNotifiesAfterFlush()
{
$batch = $this->getMock('Guzzle\Batch\Batch', array('flush'), array(
$this->getMock('Guzzle\Batch\BatchTransferInterface'),
$this->getMock('Guzzle\Batch\BatchDivisorInterface')
));
$batch->expects($this->once())
->method('flush')
->will($this->returnValue(array('foo', 'baz')));
$data = array();
$decorator = new NotifyingBatch($batch, function ($batch) use (&$data) {
$data[] = $batch;
});
$decorator->add('foo')->add('baz');
$decorator->flush();
$this->assertEquals(array(array('foo', 'baz')), $data);
}
/**
* @expectedException Guzzle\Common\Exception\InvalidArgumentException
*/
public function testEnsuresCallableIsValid()
{
$batch = new Batch(
$this->getMock('Guzzle\Batch\BatchTransferInterface'),
$this->getMock('Guzzle\Batch\BatchDivisorInterface')
);
$decorator = new NotifyingBatch($batch, 'foo');
}
}