FireAndForgetTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 PredisTestCase;
  12. use Predis\Client;
  13. use Predis\Profile;
  14. /**
  15. *
  16. */
  17. class FireAndForgetTest extends PredisTestCase
  18. {
  19. /**
  20. * @group disconnected
  21. */
  22. public function testPipelineWithSingleConnection()
  23. {
  24. $profile = Profile\Factory::getDefault();
  25. $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
  26. $connection->expects($this->exactly(3))->method('writeRequest');
  27. $connection->expects($this->never())->method('readResponse');
  28. $pipeline = new FireAndForget(new Client($connection));
  29. $pipeline->ping();
  30. $pipeline->ping();
  31. $pipeline->ping();
  32. $this->assertEmpty($pipeline->execute());
  33. }
  34. /**
  35. * @group disconnected
  36. */
  37. public function testSwitchesToMasterWithReplicationConnection()
  38. {
  39. $profile = Profile\Factory::getDefault();
  40. $connection = $this->getMock('Predis\Connection\Aggregate\ReplicationInterface');
  41. $connection->expects($this->once())
  42. ->method('switchTo')
  43. ->with('master');
  44. $connection->expects($this->exactly(3))
  45. ->method('writeRequest');
  46. $connection->expects($this->never())
  47. ->method('readResponse');
  48. $pipeline = new FireAndForget(new Client($connection));
  49. $pipeline->ping();
  50. $pipeline->ping();
  51. $pipeline->ping();
  52. $this->assertEmpty($pipeline->execute());
  53. }
  54. }