123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace Predis\Pipeline;
- use \PHPUnit_Framework_TestCase as StandardTestCase;
- use SplQueue;
- use Predis\Profile\ServerProfile;
- class FireAndForgetExecutorTest extends StandardTestCase
- {
-
- public function testExecutorWithSingleConnection()
- {
- $executor = new FireAndForgetExecutor();
- $pipeline = $this->getCommandsQueue();
- $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
- $connection->expects($this->exactly(3))
- ->method('writeCommand');
- $connection->expects($this->never())
- ->method('readResponse');
- $replies = $executor->execute($connection, $pipeline);
- $this->assertTrue($pipeline->isEmpty());
- $this->assertEmpty($replies);
- }
-
- public function testExecutorWithReplicationConnection()
- {
- $executor = new FireAndForgetExecutor();
- $pipeline = $this->getCommandsQueue();
- $connection = $this->getMock('Predis\Connection\ReplicationConnectionInterface');
- $connection->expects($this->once())
- ->method('switchTo')
- ->with('master');
- $connection->expects($this->exactly(3))
- ->method('writeCommand');
- $connection->expects($this->never())
- ->method('readResponse');
- $replies = $executor->execute($connection, $pipeline);
- $this->assertTrue($pipeline->isEmpty());
- $this->assertEmpty($replies);
- }
-
-
-
-
- protected function getCommandsQueue()
- {
- $profile = ServerProfile::getDevelopment();
- $pipeline = new SplQueue();
- $pipeline->enqueue($profile->createCommand('ping'));
- $pipeline->enqueue($profile->createCommand('ping'));
- $pipeline->enqueue($profile->createCommand('ping'));
- return $pipeline;
- }
- }
|