FireAndForgetTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Pipeline;
  11. use Predis\Client;
  12. use PredisTestCase;
  13. /**
  14. *
  15. */
  16. class FireAndForgetTest extends PredisTestCase
  17. {
  18. /**
  19. * @group disconnected
  20. */
  21. public function testPipelineWithSingleConnection()
  22. {
  23. $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
  24. $connection->expects($this->exactly(3))->method('writeRequest');
  25. $connection->expects($this->never())->method('readResponse');
  26. $pipeline = new FireAndForget(new Client($connection));
  27. $pipeline->ping();
  28. $pipeline->ping();
  29. $pipeline->ping();
  30. $this->assertEmpty($pipeline->execute());
  31. }
  32. /**
  33. * @group disconnected
  34. */
  35. public function testSwitchesToMasterWithReplicationConnection()
  36. {
  37. $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface');
  38. $connection->expects($this->once())
  39. ->method('switchToMaster');
  40. $connection->expects($this->exactly(3))
  41. ->method('writeRequest');
  42. $connection->expects($this->never())
  43. ->method('readResponse');
  44. $pipeline = new FireAndForget(new Client($connection));
  45. $pipeline->ping();
  46. $pipeline->ping();
  47. $pipeline->ping();
  48. $this->assertEmpty($pipeline->execute());
  49. }
  50. }