UdpSocketTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Monolog\Handler;
  3. use Monolog\TestCase;
  4. class UdpSocketTest extends TestCase
  5. {
  6. public function testWeDoNotSplitShortMessages()
  7. {
  8. $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('send'), array('lol', 'lol'));
  9. $socket->expects($this->at(0))
  10. ->method('send')
  11. ->with("HEADER: The quick brown fox jumps over the lazy dog");
  12. $socket->write("The quick brown fox jumps over the lazy dog", "HEADER: ");
  13. }
  14. public function testWeSplitLongMessages()
  15. {
  16. $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('send'), array('lol', 'lol'));
  17. $socket->expects($this->at(1))
  18. ->method('send')
  19. ->with("The quick brown fox jumps over the lazy dog");
  20. $aStringOfLength2048 = str_repeat("derp", 2048/4);
  21. $socket->write($aStringOfLength2048."The quick brown fox jumps over the lazy dog");
  22. }
  23. public function testAllSplitMessagesHasAHeader()
  24. {
  25. $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('send'), array('lol', 'lol'));
  26. $socket->expects($this->exactly(5))
  27. ->method('send')
  28. ->with($this->stringStartsWith("HEADER"));
  29. $aStringOfLength8192 = str_repeat("derp", 2048);
  30. $socket->write($aStringOfLength8192, "HEADER");
  31. }
  32. }