scratch – Blame information for rev 122
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | 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\Formatter; |
||
13 | |||
14 | use Monolog\Logger; |
||
15 | |||
16 | class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | /** |
||
19 | * @covers Monolog\Formatter\ChromePHPFormatter::format |
||
20 | */ |
||
21 | public function testDefaultFormat() |
||
22 | { |
||
23 | $formatter = new ChromePHPFormatter(); |
||
24 | $record = array( |
||
25 | 'level' => Logger::ERROR, |
||
26 | 'level_name' => 'ERROR', |
||
27 | 'channel' => 'meh', |
||
28 | 'context' => array('from' => 'logger'), |
||
29 | 'datetime' => new \DateTime("@0"), |
||
30 | 'extra' => array('ip' => '127.0.0.1'), |
||
31 | 'message' => 'log', |
||
32 | ); |
||
33 | |||
34 | $message = $formatter->format($record); |
||
35 | |||
36 | $this->assertEquals( |
||
37 | array( |
||
38 | 'meh', |
||
39 | array( |
||
40 | 'message' => 'log', |
||
41 | 'context' => array('from' => 'logger'), |
||
42 | 'extra' => array('ip' => '127.0.0.1'), |
||
43 | ), |
||
44 | 'unknown', |
||
45 | 'error', |
||
46 | ), |
||
47 | $message |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @covers Monolog\Formatter\ChromePHPFormatter::format |
||
53 | */ |
||
54 | public function testFormatWithFileAndLine() |
||
55 | { |
||
56 | $formatter = new ChromePHPFormatter(); |
||
57 | $record = array( |
||
58 | 'level' => Logger::CRITICAL, |
||
59 | 'level_name' => 'CRITICAL', |
||
60 | 'channel' => 'meh', |
||
61 | 'context' => array('from' => 'logger'), |
||
62 | 'datetime' => new \DateTime("@0"), |
||
63 | 'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14), |
||
64 | 'message' => 'log', |
||
65 | ); |
||
66 | |||
67 | $message = $formatter->format($record); |
||
68 | |||
69 | $this->assertEquals( |
||
70 | array( |
||
71 | 'meh', |
||
72 | array( |
||
73 | 'message' => 'log', |
||
74 | 'context' => array('from' => 'logger'), |
||
75 | 'extra' => array('ip' => '127.0.0.1'), |
||
76 | ), |
||
77 | 'test : 14', |
||
78 | 'error', |
||
79 | ), |
||
80 | $message |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @covers Monolog\Formatter\ChromePHPFormatter::format |
||
86 | */ |
||
87 | public function testFormatWithoutContext() |
||
88 | { |
||
89 | $formatter = new ChromePHPFormatter(); |
||
90 | $record = array( |
||
91 | 'level' => Logger::DEBUG, |
||
92 | 'level_name' => 'DEBUG', |
||
93 | 'channel' => 'meh', |
||
94 | 'context' => array(), |
||
95 | 'datetime' => new \DateTime("@0"), |
||
96 | 'extra' => array(), |
||
97 | 'message' => 'log', |
||
98 | ); |
||
99 | |||
100 | $message = $formatter->format($record); |
||
101 | |||
102 | $this->assertEquals( |
||
103 | array( |
||
104 | 'meh', |
||
105 | 'log', |
||
106 | 'unknown', |
||
107 | 'log', |
||
108 | ), |
||
109 | $message |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @covers Monolog\Formatter\ChromePHPFormatter::formatBatch |
||
115 | */ |
||
116 | public function testBatchFormatThrowException() |
||
117 | { |
||
118 | $formatter = new ChromePHPFormatter(); |
||
119 | $records = array( |
||
120 | array( |
||
121 | 'level' => Logger::INFO, |
||
122 | 'level_name' => 'INFO', |
||
123 | 'channel' => 'meh', |
||
124 | 'context' => array(), |
||
125 | 'datetime' => new \DateTime("@0"), |
||
126 | 'extra' => array(), |
||
127 | 'message' => 'log', |
||
128 | ), |
||
129 | array( |
||
130 | 'level' => Logger::WARNING, |
||
131 | 'level_name' => 'WARNING', |
||
132 | 'channel' => 'foo', |
||
133 | 'context' => array(), |
||
134 | 'datetime' => new \DateTime("@0"), |
||
135 | 'extra' => array(), |
||
136 | 'message' => 'log2', |
||
137 | ), |
||
138 | ); |
||
139 | |||
140 | $this->assertEquals( |
||
141 | array( |
||
142 | array( |
||
143 | 'meh', |
||
144 | 'log', |
||
145 | 'unknown', |
||
146 | 'info', |
||
147 | ), |
||
148 | array( |
||
149 | 'foo', |
||
150 | 'log2', |
||
151 | 'unknown', |
||
152 | 'warn', |
||
153 | ), |
||
154 | ), |
||
155 | $formatter->formatBatch($records) |
||
156 | ); |
||
157 | } |
||
158 | } |