scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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  
14 use Monolog\TestCase;
15  
16 /**
17 * @requires extension sockets
18 */
19 class SyslogUdpHandlerTest extends TestCase
20 {
21 /**
22 * @expectedException UnexpectedValueException
23 */
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 }