UdpSocketTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  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 Monolog\Handler;
  11. use Monolog\Test\TestCase;
  12. use Monolog\Handler\SyslogUdp\UdpSocket;
  13. /**
  14. * @requires extension sockets
  15. */
  16. class UdpSocketTest extends TestCase
  17. {
  18. public function testWeDoNotTruncateShortMessages()
  19. {
  20. $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('send'), array('lol', 'lol'));
  21. $socket->expects($this->at(0))
  22. ->method('send')
  23. ->with("HEADER: The quick brown fox jumps over the lazy dog");
  24. $socket->write("The quick brown fox jumps over the lazy dog", "HEADER: ");
  25. }
  26. public function testLongMessagesAreTruncated()
  27. {
  28. $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('send'), array('lol', 'lol'));
  29. $truncatedString = str_repeat("derp", 16254).'d';
  30. $socket->expects($this->exactly(1))
  31. ->method('send')
  32. ->with("HEADER" . $truncatedString);
  33. $longString = str_repeat("derp", 20000);
  34. $socket->write($longString, "HEADER");
  35. }
  36. public function testDoubleCloseDoesNotError()
  37. {
  38. $socket = new UdpSocket('127.0.0.1', 514);
  39. $socket->close();
  40. $socket->close();
  41. }
  42. /**
  43. * @expectedException LogicException
  44. */
  45. public function testWriteAfterCloseErrors()
  46. {
  47. $socket = new UdpSocket('127.0.0.1', 514);
  48. $socket->close();
  49. $socket->write('foo', "HEADER");
  50. }
  51. }