FireAndForgetTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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
  25. ->expects($this->exactly(3))
  26. ->method('writeRequest');
  27. $connection
  28. ->expects($this->never())
  29. ->method('readResponse');
  30. $pipeline = new FireAndForget(new Client($connection));
  31. $pipeline->ping();
  32. $pipeline->ping();
  33. $pipeline->ping();
  34. $this->assertEmpty($pipeline->execute());
  35. }
  36. /**
  37. * @group disconnected
  38. */
  39. public function testSwitchesToMasterWithReplicationConnection()
  40. {
  41. $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface');
  42. $connection
  43. ->expects($this->once())
  44. ->method('switchToMaster');
  45. $connection
  46. ->expects($this->exactly(3))
  47. ->method('writeRequest');
  48. $connection
  49. ->expects($this->never())
  50. ->method('readResponse');
  51. $pipeline = new FireAndForget(new Client($connection));
  52. $pipeline->ping();
  53. $pipeline->ping();
  54. $pipeline->ping();
  55. $this->assertEmpty($pipeline->execute());
  56. }
  57. }