BufferTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace React\ZMQ;
  3. class BufferTest extends \PHPUnit_Framework_TestCase
  4. {
  5. /** @test */
  6. public function sendShouldQueueMessages()
  7. {
  8. $loop = $this->getMock('React\EventLoop\LoopInterface');
  9. $loop
  10. ->expects($this->once())
  11. ->method('addWriteStream');
  12. $socket = $this->getMockBuilder('ZMQSocket')->disableOriginalConstructor()->getMock();
  13. $socket
  14. ->expects($this->never())
  15. ->method('send');
  16. $writeListener = function () {};
  17. $buffer = new Buffer($socket, 42, $loop, $writeListener);
  18. $buffer->send('foo');
  19. }
  20. /** @test */
  21. public function loopShouldSendQueuedMessages()
  22. {
  23. $writeListener = function () {};
  24. $loop = $this->getMock('React\EventLoop\LoopInterface');
  25. $loop
  26. ->expects($this->once())
  27. ->method('addWriteStream')
  28. ->with($this->isType('integer'), $writeListener);
  29. $socket = $this->getMockBuilder('ZMQSocket')->disableOriginalConstructor()->getMock();
  30. $socket
  31. ->expects($this->at(0))
  32. ->method('sendmulti')
  33. ->with(array('foo'), \ZMQ::MODE_DONTWAIT)
  34. ->will($this->returnSelf());
  35. $socket
  36. ->expects($this->at(1))
  37. ->method('sendmulti')
  38. ->with(array('bar'), \ZMQ::MODE_DONTWAIT)
  39. ->will($this->returnSelf());
  40. $buffer = new Buffer($socket, 42, $loop, $writeListener);
  41. $buffer->send('foo');
  42. $buffer->send('bar');
  43. $buffer->handleWriteEvent();
  44. }
  45. }