SyslogUdpHandlerTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Monolog\Handler;
  3. use Monolog\TestCase;
  4. class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase
  5. {
  6. /**
  7. * @expectedException UnexpectedValueException
  8. */
  9. public function testWeValidateFacilities()
  10. {
  11. $handler = new SyslogUdpHandler("ip", null, "invalidFacility");
  12. }
  13. public function testWeSplitIntoLines()
  14. {
  15. $handler = new SyslogUdpHandler("127.0.0.1", 514, "local5");
  16. $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
  17. $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('write'), array('lol', 'lol'));
  18. $socket->expects($this->at(0))
  19. ->method('write')
  20. ->with("lol", "<172>: ");
  21. $socket->expects($this->at(1))
  22. ->method('write')
  23. ->with("hej", "<172>: ");
  24. $handler->setSocket($socket);
  25. $handler->handle($this->getRecordWithMessage("hej\nlol"));
  26. }
  27. protected function getRecordWithMessage($msg)
  28. {
  29. return array('message' => $msg, 'level' => \Monolog\Logger::WARNING, 'context' => null, 'extra' => array(), 'channel' => 'lol');
  30. }
  31. }