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 use Monolog\Logger;
16 use Monolog\Formatter\LineFormatter;
17  
18 function error_log()
19 {
20 $GLOBALS['error_log'][] = func_get_args();
21 }
22  
23 class ErrorLogHandlerTest extends TestCase
24 {
25 protected function setUp()
26 {
27 $GLOBALS['error_log'] = array();
28 }
29  
30 /**
31 * @covers Monolog\Handler\ErrorLogHandler::__construct
32 * @expectedException InvalidArgumentException
33 * @expectedExceptionMessage The given message type "42" is not supported
34 */
35 public function testShouldNotAcceptAnInvalidTypeOnContructor()
36 {
37 new ErrorLogHandler(42);
38 }
39  
40 /**
41 * @covers Monolog\Handler\ErrorLogHandler::write
42 */
43 public function testShouldLogMessagesUsingErrorLogFuncion()
44 {
45 $type = ErrorLogHandler::OPERATING_SYSTEM;
46 $handler = new ErrorLogHandler($type);
47 $handler->setFormatter(new LineFormatter('%channel%.%level_name%: %message% %context% %extra%', null, true));
48 $handler->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz"));
49  
50 $this->assertSame("test.ERROR: Foo\nBar\r\n\r\nBaz [] []", $GLOBALS['error_log'][0][0]);
51 $this->assertSame($GLOBALS['error_log'][0][1], $type);
52  
53 $handler = new ErrorLogHandler($type, Logger::DEBUG, true, true);
54 $handler->setFormatter(new LineFormatter(null, null, true));
55 $handler->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz"));
56  
57 $this->assertStringMatchesFormat('[%s] test.ERROR: Foo', $GLOBALS['error_log'][1][0]);
58 $this->assertSame($GLOBALS['error_log'][1][1], $type);
59  
60 $this->assertStringMatchesFormat('Bar', $GLOBALS['error_log'][2][0]);
61 $this->assertSame($GLOBALS['error_log'][2][1], $type);
62  
63 $this->assertStringMatchesFormat('Baz [] []', $GLOBALS['error_log'][3][0]);
64 $this->assertSame($GLOBALS['error_log'][3][1], $type);
65 }
66 }