SyslogUdpHandlerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /**
  12. * @requires extension sockets
  13. */
  14. class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @expectedException UnexpectedValueException
  18. */
  19. public function testWeValidateFacilities()
  20. {
  21. $handler = new SyslogUdpHandler("ip", null, "invalidFacility");
  22. }
  23. public function testWeSplitIntoLines()
  24. {
  25. $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv");
  26. $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
  27. $socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket')
  28. ->setMethods(['write'])
  29. ->setConstructorArgs(['lol', 'lol'])
  30. ->getMock();
  31. $socket->expects($this->at(0))
  32. ->method('write')
  33. ->with("lol", "<".(LOG_AUTHPRIV + LOG_WARNING).">1 ");
  34. $socket->expects($this->at(1))
  35. ->method('write')
  36. ->with("hej", "<".(LOG_AUTHPRIV + LOG_WARNING).">1 ");
  37. $handler->setSocket($socket);
  38. $handler->handle($this->getRecordWithMessage("hej\nlol"));
  39. }
  40. protected function getRecordWithMessage($msg)
  41. {
  42. return ['message' => $msg, 'level' => \Monolog\Logger::WARNING, 'context' => null, 'extra' => [], 'channel' => 'lol'];
  43. }
  44. }