ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SyslogUdpHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Handler;
13 
15 
20 {
24  public function testWeValidateFacilities()
25  {
26  $handler = new SyslogUdpHandler("ip", null, "invalidFacility");
27  }
28 
29  public function testWeSplitIntoLines()
30  {
31  $time = '2014-01-07T12:34';
32  $pid = getmypid();
33  $host = gethostname();
34 
35  $handler = $this->getMockBuilder('\Monolog\Handler\SyslogUdpHandler')
36  ->setConstructorArgs(array("127.0.0.1", 514, "authpriv"))
37  ->setMethods(array('getDateTime'))
38  ->getMock();
39 
40  $handler->method('getDateTime')
41  ->willReturn($time);
42 
43  $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
44 
45  $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('write'), array('lol', 'lol'));
46  $socket->expects($this->at(0))
47  ->method('write')
48  ->with("lol", "<".(LOG_AUTHPRIV + LOG_WARNING).">1 $time $host php $pid - - ");
49  $socket->expects($this->at(1))
50  ->method('write')
51  ->with("hej", "<".(LOG_AUTHPRIV + LOG_WARNING).">1 $time $host php $pid - - ");
52 
53  $handler->setSocket($socket);
54 
55  $handler->handle($this->getRecordWithMessage("hej\nlol"));
56  }
57 
58  public function testSplitWorksOnEmptyMsg()
59  {
60  $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv");
61  $handler->setFormatter($this->getIdentityFormatter());
62 
63  $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('write'), array('lol', 'lol'));
64  $socket->expects($this->never())
65  ->method('write');
66 
67  $handler->setSocket($socket);
68 
69  $handler->handle($this->getRecordWithMessage(null));
70  }
71 
72  protected function getRecordWithMessage($msg)
73  {
74  return array('message' => $msg, 'level' => \Monolog\Logger::WARNING, 'context' => null, 'extra' => array(), 'channel' => 'lol');
75  }
76 }
testWeValidateFacilities()
UnexpectedValueException
Formats a log message according to the ChromePHP array format.
A Handler for logging to a remote syslogd server.
$time
Definition: cron.php:21
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
$handler