ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
IntrospectionProcessorTest.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
12namespace Acme;
13
14class Tester
15{
16 public function test($handler, $record)
17 {
18 $handler->handle($record);
19 }
20}
21
22function tester($handler, $record)
23{
24 $handler->handle($record);
25}
26
27namespace Monolog\Processor;
28
32
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
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
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
119 $actual = $processor($input);
120
121 $this->assertEquals($expected, $actual);
122 }
123}
test($handler, $record)
Used for testing purposes.
Definition: TestHandler.php:69
Monolog log channel.
Definition: Logger.php:28
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Injects line/file:class/function where the log message came from.
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
tester($handler, $record)