ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
NewRelicHandlerTest.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 Monolog\Handler;
13
16
18{
19 public static $appname;
20 public static $customParameters;
21 public static $transactionName;
22
23 public function setUp()
24 {
25 self::$appname = null;
26 self::$customParameters = array();
27 self::$transactionName = null;
28 }
29
34 {
36 $handler->handle($this->getRecord(Logger::ERROR));
37 }
38
40 {
41 $handler = new StubNewRelicHandler();
42 $handler->handle($this->getRecord(Logger::ERROR));
43 }
44
46 {
47 $handler = new StubNewRelicHandler();
48 $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('a' => 'b')));
49 $this->assertEquals(array('context_a' => 'b'), self::$customParameters);
50 }
51
53 {
54 $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
55 $handler->handle($this->getRecord(
57 'log message',
58 array('a' => array('key1' => 'value1', 'key2' => 'value2'))
59 ));
60 $this->assertEquals(
61 array('context_a_key1' => 'value1', 'context_a_key2' => 'value2'),
62 self::$customParameters
63 );
64 }
65
67 {
68 $record = $this->getRecord(Logger::ERROR, 'log message');
69 $record['extra'] = array('c' => 'd');
70
71 $handler = new StubNewRelicHandler();
72 $handler->handle($record);
73
74 $this->assertEquals(array('extra_c' => 'd'), self::$customParameters);
75 }
76
78 {
79 $record = $this->getRecord(Logger::ERROR, 'log message');
80 $record['extra'] = array('c' => array('key1' => 'value1', 'key2' => 'value2'));
81
82 $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
83 $handler->handle($record);
84
85 $this->assertEquals(
86 array('extra_c_key1' => 'value1', 'extra_c_key2' => 'value2'),
87 self::$customParameters
88 );
89 }
90
92 {
93 $record = $this->getRecord(Logger::ERROR, 'log message', array('a' => 'b'));
94 $record['extra'] = array('c' => 'd');
95
96 $handler = new StubNewRelicHandler();
97 $handler->handle($record);
98
99 $expected = array(
100 'context_a' => 'b',
101 'extra_c' => 'd',
102 );
103
104 $this->assertEquals($expected, self::$customParameters);
105 }
106
108 {
109 $handler = new StubNewRelicHandler();
110 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
111
112 $this->assertEquals(null, self::$appname);
113 }
114
116 {
117 $handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
118 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
119
120 $this->assertEquals('myAppName', self::$appname);
121 }
122
124 {
125 $handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
126 $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'logAppName')));
127
128 $this->assertEquals('logAppName', self::$appname);
129 }
130
132 {
133 $handler = new StubNewRelicHandler();
134 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
135
136 $this->assertEquals(null, self::$transactionName);
137 }
138
140 {
141 $handler = new StubNewRelicHandler(Logger::DEBUG, false, null, false, 'myTransaction');
142 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
143
144 $this->assertEquals('myTransaction', self::$transactionName);
145 }
146
148 {
149 $handler = new StubNewRelicHandler(Logger::DEBUG, false, null, false, 'myTransaction');
150 $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('transaction_name' => 'logTransactName')));
151
152 $this->assertEquals('logTransactName', self::$transactionName);
153 }
154}
155
157{
158 protected function isNewRelicEnabled()
159 {
160 return false;
161 }
162}
163
165{
166 protected function isNewRelicEnabled()
167 {
168 return true;
169 }
170}
171
173{
174 return true;
175}
176
177function newrelic_set_appname($appname)
178{
179 return NewRelicHandlerTest::$appname = $appname;
180}
181
182function newrelic_name_transaction($transactionName)
183{
184 return NewRelicHandlerTest::$transactionName = $transactionName;
185}
186
187function newrelic_add_custom_parameter($key, $value)
188{
190
191 return true;
192}
testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
@expectedException Monolog\Handler\MissingExtensionException
Class to record a log on a NewRelic application.
isNewRelicEnabled()
Checks whether the NewRelic extension is enabled in the system.
isNewRelicEnabled()
Checks whether the NewRelic extension is enabled in the system.
Monolog log channel.
Definition: Logger.php:28
const ERROR
Runtime errors.
Definition: Logger.php:57
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
newrelic_set_appname($appname)
newrelic_add_custom_parameter($key, $value)
newrelic_name_transaction($transactionName)