FireAndForgetTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Aggregate\ReplicationInterface');
  38. $connection->expects($this->once())
  39. ->method('switchTo')
  40. ->with('master');
  41. $connection->expects($this->exactly(3))
  42. ->method('writeRequest');
  43. $connection->expects($this->never())
  44. ->method('readResponse');
  45. $pipeline = new FireAndForget(new Client($connection));
  46. $pipeline->ping();
  47. $pipeline->ping();
  48. $pipeline->ping();
  49. $this->assertEmpty($pipeline->execute());
  50. }
  51. }