UdpSocketTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php declare(strict_types=1);
  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\Handler\SyslogUdp\UdpSocket;
  12. use Monolog\Test\TestCase;
  13. /**
  14. * @requires extension sockets
  15. */
  16. class UdpSocketTest extends TestCase
  17. {
  18. public function testWeDoNotTruncateShortMessages()
  19. {
  20. $socket = $this->getMockBuilder('Monolog\Handler\SyslogUdp\UdpSocket')
  21. ->onlyMethods(['send'])
  22. ->setConstructorArgs(['lol'])
  23. ->getMock();
  24. $socket
  25. ->method('send')
  26. ->with("HEADER: The quick brown fox jumps over the lazy dog");
  27. $socket->write("The quick brown fox jumps over the lazy dog", "HEADER: ");
  28. }
  29. public function testLongMessagesAreTruncated()
  30. {
  31. $socket = $this->getMockBuilder('Monolog\Handler\SyslogUdp\UdpSocket')
  32. ->onlyMethods(['send'])
  33. ->setConstructorArgs(['lol'])
  34. ->getMock();
  35. $truncatedString = str_repeat("derp", 16254).'d';
  36. $socket->expects($this->exactly(1))
  37. ->method('send')
  38. ->with("HEADER" . $truncatedString);
  39. $longString = str_repeat("derp", 20000);
  40. $socket->write($longString, "HEADER");
  41. }
  42. public function testDoubleCloseDoesNotError()
  43. {
  44. $socket = new UdpSocket('127.0.0.1', 514);
  45. $socket->close();
  46. $socket->close();
  47. }
  48. public function testWriteAfterCloseReopened()
  49. {
  50. $socket = new UdpSocket('127.0.0.1', 514);
  51. $socket->close();
  52. $socket->write('foo', "HEADER");
  53. }
  54. }