ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
17
19{
20 public static $appname;
21 public static $customParameters;
22 public static $transactionName;
23
24 public function setUp()
25 {
26 self::$appname = null;
27 self::$customParameters = array();
28 self::$transactionName = null;
29 }
30
35 {
37 $handler->handle($this->getRecord(Logger::ERROR));
38 }
39
41 {
43 $handler->handle($this->getRecord(Logger::ERROR));
44 }
45
47 {
49 $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('a' => 'b')));
50 $this->assertEquals(array('context_a' => 'b'), self::$customParameters);
51 }
52
54 {
55 $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
56 $handler->handle($this->getRecord(
58 'log message',
59 array('a' => array('key1' => 'value1', 'key2' => 'value2'))
60 ));
61 $this->assertEquals(
62 array('context_a_key1' => 'value1', 'context_a_key2' => 'value2'),
63 self::$customParameters
64 );
65 }
66
68 {
69 $record = $this->getRecord(Logger::ERROR, 'log message');
70 $record['extra'] = array('c' => 'd');
71
73 $handler->handle($record);
74
75 $this->assertEquals(array('extra_c' => 'd'), self::$customParameters);
76 }
77
79 {
80 $record = $this->getRecord(Logger::ERROR, 'log message');
81 $record['extra'] = array('c' => array('key1' => 'value1', 'key2' => 'value2'));
82
83 $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
84 $handler->handle($record);
85
86 $this->assertEquals(
87 array('extra_c_key1' => 'value1', 'extra_c_key2' => 'value2'),
88 self::$customParameters
89 );
90 }
91
93 {
94 $record = $this->getRecord(Logger::ERROR, 'log message', array('a' => 'b'));
95 $record['extra'] = array('c' => 'd');
96
98 $handler->handle($record);
99
100 $expected = array(
101 'context_a' => 'b',
102 'extra_c' => 'd',
103 );
104
105 $this->assertEquals($expected, self::$customParameters);
106 }
107
109 {
111 $handler->setFormatter(new LineFormatter());
112 $handler->handle($this->getRecord(Logger::ERROR));
113 }
114
116 {
118 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
119
120 $this->assertEquals(null, self::$appname);
121 }
122
124 {
125 $handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
126 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
127
128 $this->assertEquals('myAppName', self::$appname);
129 }
130
132 {
133 $handler = new StubNewRelicHandler(Logger::DEBUG, false, 'myAppName');
134 $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'logAppName')));
135
136 $this->assertEquals('logAppName', self::$appname);
137 }
138
140 {
142 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
143
144 $this->assertEquals(null, self::$transactionName);
145 }
146
148 {
149 $handler = new StubNewRelicHandler(Logger::DEBUG, false, null, false, 'myTransaction');
150 $handler->handle($this->getRecord(Logger::ERROR, 'log message'));
151
152 $this->assertEquals('myTransaction', self::$transactionName);
153 }
154
156 {
157 $handler = new StubNewRelicHandler(Logger::DEBUG, false, null, false, 'myTransaction');
158 $handler->handle($this->getRecord(Logger::ERROR, 'log message', array('transaction_name' => 'logTransactName')));
159
160 $this->assertEquals('logTransactName', self::$transactionName);
161 }
162}
163
165{
166 protected function isNewRelicEnabled()
167 {
168 return false;
169 }
170}
171
173{
174 protected function isNewRelicEnabled()
175 {
176 return true;
177 }
178}
179
181{
182 return true;
183}
184
185function newrelic_set_appname($appname)
186{
187 return NewRelicHandlerTest::$appname = $appname;
188}
189
190function newrelic_name_transaction($transactionName)
191{
192 return NewRelicHandlerTest::$transactionName = $transactionName;
193}
194
196{
198
199 return true;
200}
An exception for terminatinating execution or to throw for unit testing.
Formats incoming records into a one-line string.
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
$key
Definition: croninfo.php:18
newrelic_set_appname($appname)
newrelic_add_custom_parameter($key, $value)
newrelic_name_transaction($transactionName)
$handler