]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - vendor/monolog/monolog/tests/Monolog/Processor/IntrospectionProcessorTest.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / vendor / monolog / monolog / tests / Monolog / Processor / IntrospectionProcessorTest.php
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 Acme;
13
14 class Tester
15 {
16     public function test($handler, $record)
17     {
18         $handler->handle($record);
19     }
20 }
21
22 function tester($handler, $record)
23 {
24     $handler->handle($record);
25 }
26
27 namespace Monolog\Processor;
28
29 use Monolog\Logger;
30 use Monolog\TestCase;
31 use Monolog\Handler\TestHandler;
32
33 class IntrospectionProcessorTest extends TestCase
34 {
35     public function getHandler()
36     {
37         $processor = new IntrospectionProcessor();
38         $handler = new TestHandler();
39         $handler->pushProcessor($processor);
40
41         return $handler;
42     }
43
44     public function testProcessorFromClass()
45     {
46         $handler = $this->getHandler();
47         $tester = new \Acme\Tester;
48         $tester->test($handler, $this->getRecord());
49         list($record) = $handler->getRecords();
50         $this->assertEquals(__FILE__, $record['extra']['file']);
51         $this->assertEquals(18, $record['extra']['line']);
52         $this->assertEquals('Acme\Tester', $record['extra']['class']);
53         $this->assertEquals('test', $record['extra']['function']);
54     }
55
56     public function testProcessorFromFunc()
57     {
58         $handler = $this->getHandler();
59         \Acme\tester($handler, $this->getRecord());
60         list($record) = $handler->getRecords();
61         $this->assertEquals(__FILE__, $record['extra']['file']);
62         $this->assertEquals(24, $record['extra']['line']);
63         $this->assertEquals(null, $record['extra']['class']);
64         $this->assertEquals('Acme\tester', $record['extra']['function']);
65     }
66
67     public function testLevelTooLow()
68     {
69         $input = array(
70             'level' => Logger::DEBUG,
71             'extra' => array(),
72         );
73
74         $expected = $input;
75
76         $processor = new IntrospectionProcessor(Logger::CRITICAL);
77         $actual = $processor($input);
78
79         $this->assertEquals($expected, $actual);
80     }
81
82     public function testLevelEqual()
83     {
84         $input = array(
85             'level' => Logger::CRITICAL,
86             'extra' => array(),
87         );
88
89         $expected = $input;
90         $expected['extra'] = array(
91             'file' => null,
92             'line' => null,
93             'class' => 'ReflectionMethod',
94             'function' => 'invokeArgs',
95         );
96
97         $processor = new IntrospectionProcessor(Logger::CRITICAL);
98         $actual = $processor($input);
99
100         $this->assertEquals($expected, $actual);
101     }
102
103     public function testLevelHigher()
104     {
105         $input = array(
106             'level' => Logger::EMERGENCY,
107             'extra' => array(),
108         );
109
110         $expected = $input;
111         $expected['extra'] = array(
112             'file' => null,
113             'line' => null,
114             'class' => 'ReflectionMethod',
115             'function' => 'invokeArgs',
116         );
117
118         $processor = new IntrospectionProcessor(Logger::CRITICAL);
119         $actual = $processor($input);
120
121         $this->assertEquals($expected, $actual);
122     }
123 }