SyslogUdpHandlerTest.php 1.2 KB

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