FireAndForgetTest.php 1.8 KB

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