ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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 
12 namespace Monolog\Handler;
13 
16 use Monolog\Logger;
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  {
36  $handler = new StubNewRelicHandlerWithoutExtension();
37  $handler->handle($this->getRecord(Logger::ERROR));
38  }
39 
41  {
42  $handler = new StubNewRelicHandler();
43  $handler->handle($this->getRecord(Logger::ERROR));
44  }
45 
47  {
48  $handler = new StubNewRelicHandler();
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 
72  $handler = new StubNewRelicHandler();
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 
97  $handler = new StubNewRelicHandler();
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  {
110  $handler = new StubNewRelicHandler();
111  $handler->setFormatter(new LineFormatter());
112  $handler->handle($this->getRecord(Logger::ERROR));
113  }
114 
116  {
117  $handler = new StubNewRelicHandler();
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  {
141  $handler = new StubNewRelicHandler();
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 
186 {
188 }
189 
191 {
193 }
194 
195 function newrelic_add_custom_parameter($key, $value)
196 {
198 
199  return true;
200 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const ERROR
Runtime errors.
Definition: Logger.php:57
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Class to record a log on a NewRelic application.
newrelic_add_custom_parameter($key, $value)
Create styles array
The data for the language used.
newrelic_name_transaction($transactionName)
testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
Monolog
Formats incoming records into a one-line string.
newrelic_set_appname($appname)