ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\RavenHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\RavenHandlerTest:
+ Collaboration diagram for Monolog\Handler\RavenHandlerTest:

Public Member Functions

 setUp ()
 
 testConstruct ()
 @covers Monolog\Handler\RavenHandler::__construct More...
 
 testDebug ()
 
 testWarning ()
 
 testTag ()
 
 testExtraParameters ()
 
 testFingerprint ()
 
 testUserContext ()
 
 testException ()
 
 testHandleBatch ()
 
 testHandleBatchDoNothingIfRecordsAreBelowLevel ()
 
 testHandleBatchPicksProperMessage ()
 
 testGetSetBatchFormatter ()
 
 testRelease ()
 

Protected Member Functions

 getHandler ($ravenClient)
 
 getRavenClient ()
 
- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Private Member Functions

 methodThatThrowsAnException ()
 

Detailed Description

Definition at line 18 of file RavenHandlerTest.php.

Member Function Documentation

◆ getHandler()

◆ getRavenClient()

◆ methodThatThrowsAnException()

Monolog\Handler\RavenHandlerTest::methodThatThrowsAnException ( )
private

Definition at line 251 of file RavenHandlerTest.php.

252 {
253 throw new \Exception('This is an exception');
254 }

Referenced by Monolog\Handler\RavenHandlerTest\testException().

+ Here is the caller graph for this function:

◆ setUp()

Monolog\Handler\RavenHandlerTest::setUp ( )

Definition at line 20 of file RavenHandlerTest.php.

21 {
22 if (!class_exists('Raven_Client')) {
23 $this->markTestSkipped('raven/raven not installed');
24 }
25
26 require_once __DIR__ . '/MockRavenClient.php';
27 }

◆ testConstruct()

Monolog\Handler\RavenHandlerTest::testConstruct ( )

@covers Monolog\Handler\RavenHandler::__construct

Definition at line 32 of file RavenHandlerTest.php.

33 {
34 $handler = new RavenHandler($this->getRavenClient());
35 $this->assertInstanceOf('Monolog\Handler\RavenHandler', $handler);
36 }

References $handler, and Monolog\Handler\RavenHandlerTest\getRavenClient().

+ Here is the call graph for this function:

◆ testDebug()

Monolog\Handler\RavenHandlerTest::testDebug ( )

Definition at line 52 of file RavenHandlerTest.php.

53 {
54 $ravenClient = $this->getRavenClient();
55 $handler = $this->getHandler($ravenClient);
56
57 $record = $this->getRecord(Logger::DEBUG, 'A test debug message');
58 $handler->handle($record);
59
60 $this->assertEquals($ravenClient::DEBUG, $ravenClient->lastData['level']);
61 $this->assertContains($record['message'], $ravenClient->lastData['message']);
62 }
const DEBUG
Detailed debug information.
Definition: Logger.php:33
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const DEBUG

References $handler, Monolog\Logger\DEBUG, DEBUG, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

◆ testException()

Monolog\Handler\RavenHandlerTest::testException ( )

Definition at line 151 of file RavenHandlerTest.php.

152 {
153 $ravenClient = $this->getRavenClient();
154 $handler = $this->getHandler($ravenClient);
155
156 try {
158 } catch (\Exception $e) {
159 $record = $this->getRecord(Logger::ERROR, $e->getMessage(), array('exception' => $e));
160 $handler->handle($record);
161 }
162
163 $this->assertEquals($record['message'], $ravenClient->lastData['message']);
164 }
const ERROR
Runtime errors.
Definition: Logger.php:58

References $handler, Monolog\Logger\ERROR, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Handler\RavenHandlerTest\methodThatThrowsAnException().

+ Here is the call graph for this function:

◆ testExtraParameters()

Monolog\Handler\RavenHandlerTest::testExtraParameters ( )

Definition at line 88 of file RavenHandlerTest.php.

89 {
90 $ravenClient = $this->getRavenClient();
91 $handler = $this->getHandler($ravenClient);
92
93 $checksum = '098f6bcd4621d373cade4e832627b4f6';
94 $release = '05a671c66aefea124cc08b76ea6d30bb';
95 $eventId = '31423';
96 $record = $this->getRecord(Logger::INFO, 'test', array('checksum' => $checksum, 'release' => $release, 'event_id' => $eventId));
97 $handler->handle($record);
98
99 $this->assertEquals($checksum, $ravenClient->lastData['checksum']);
100 $this->assertEquals($release, $ravenClient->lastData['release']);
101 $this->assertEquals($eventId, $ravenClient->lastData['event_id']);
102 }
const INFO
Interesting events.
Definition: Logger.php:40

References $handler, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

+ Here is the call graph for this function:

◆ testFingerprint()

Monolog\Handler\RavenHandlerTest::testFingerprint ( )

Definition at line 104 of file RavenHandlerTest.php.

105 {
106 $ravenClient = $this->getRavenClient();
107 $handler = $this->getHandler($ravenClient);
108
109 $fingerprint = array('{{ default }}', 'other value');
110 $record = $this->getRecord(Logger::INFO, 'test', array('fingerprint' => $fingerprint));
111 $handler->handle($record);
112
113 $this->assertEquals($fingerprint, $ravenClient->lastData['fingerprint']);
114 }

References $handler, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

+ Here is the call graph for this function:

◆ testGetSetBatchFormatter()

Monolog\Handler\RavenHandlerTest::testGetSetBatchFormatter ( )

Definition at line 226 of file RavenHandlerTest.php.

227 {
228 $ravenClient = $this->getRavenClient();
229 $handler = $this->getHandler($ravenClient);
230
231 $handler->setBatchFormatter($formatter = new LineFormatter());
232 $this->assertSame($formatter, $handler->getBatchFormatter());
233 }

References $handler, Monolog\Handler\RavenHandlerTest\getHandler(), and Monolog\Handler\RavenHandlerTest\getRavenClient().

+ Here is the call graph for this function:

◆ testHandleBatch()

Monolog\Handler\RavenHandlerTest::testHandleBatch ( )

Definition at line 166 of file RavenHandlerTest.php.

167 {
168 $records = $this->getMultipleRecords();
169 $records[] = $this->getRecord(Logger::WARNING, 'warning');
170 $records[] = $this->getRecord(Logger::WARNING, 'warning');
171
172 $logFormatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
173 $logFormatter->expects($this->once())->method('formatBatch');
174
175 $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
176 $formatter->expects($this->once())->method('format')->with($this->callback(function ($record) {
177 return $record['level'] == 400;
178 }));
179
180 $handler = $this->getHandler($this->getRavenClient());
181 $handler->setBatchFormatter($logFormatter);
182 $handler->setFormatter($formatter);
183 $handler->handleBatch($records);
184 }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$records
Definition: simple_test.php:22

References $handler, $records, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\TestCase\getMultipleRecords(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), Sabre\Event\once(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

◆ testHandleBatchDoNothingIfRecordsAreBelowLevel()

Monolog\Handler\RavenHandlerTest::testHandleBatchDoNothingIfRecordsAreBelowLevel ( )

Definition at line 186 of file RavenHandlerTest.php.

187 {
188 $records = array(
189 $this->getRecord(Logger::DEBUG, 'debug message 1'),
190 $this->getRecord(Logger::DEBUG, 'debug message 2'),
191 $this->getRecord(Logger::INFO, 'information'),
192 );
193
194 $handler = $this->getMock('Monolog\Handler\RavenHandler', null, array($this->getRavenClient()));
195 $handler->expects($this->never())->method('handle');
196 $handler->setLevel(Logger::ERROR);
197 $handler->handleBatch($records);
198 }

References $handler, $records, Monolog\Logger\DEBUG, Monolog\Logger\ERROR, Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

+ Here is the call graph for this function:

◆ testHandleBatchPicksProperMessage()

Monolog\Handler\RavenHandlerTest::testHandleBatchPicksProperMessage ( )

Definition at line 200 of file RavenHandlerTest.php.

201 {
202 $records = array(
203 $this->getRecord(Logger::DEBUG, 'debug message 1'),
204 $this->getRecord(Logger::DEBUG, 'debug message 2'),
205 $this->getRecord(Logger::INFO, 'information 1'),
206 $this->getRecord(Logger::ERROR, 'error 1'),
207 $this->getRecord(Logger::WARNING, 'warning'),
208 $this->getRecord(Logger::ERROR, 'error 2'),
209 $this->getRecord(Logger::INFO, 'information 2'),
210 );
211
212 $logFormatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
213 $logFormatter->expects($this->once())->method('formatBatch');
214
215 $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
216 $formatter->expects($this->once())->method('format')->with($this->callback(function ($record) use ($records) {
217 return $record['message'] == 'error 1';
218 }));
219
220 $handler = $this->getHandler($this->getRavenClient());
221 $handler->setBatchFormatter($logFormatter);
222 $handler->setFormatter($formatter);
223 $handler->handleBatch($records);
224 }

References $handler, $records, Monolog\Logger\DEBUG, Monolog\Logger\ERROR, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), Monolog\Logger\INFO, Sabre\Event\once(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

◆ testRelease()

Monolog\Handler\RavenHandlerTest::testRelease ( )

Definition at line 235 of file RavenHandlerTest.php.

236 {
237 $ravenClient = $this->getRavenClient();
238 $handler = $this->getHandler($ravenClient);
239 $release = 'v42.42.42';
240 $handler->setRelease($release);
241 $record = $this->getRecord(Logger::INFO, 'test');
242 $handler->handle($record);
243 $this->assertEquals($release, $ravenClient->lastData['release']);
244
245 $localRelease = 'v41.41.41';
246 $record = $this->getRecord(Logger::INFO, 'test', array('release' => $localRelease));
247 $handler->handle($record);
248 $this->assertEquals($localRelease, $ravenClient->lastData['release']);
249 }

References $handler, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

+ Here is the call graph for this function:

◆ testTag()

Monolog\Handler\RavenHandlerTest::testTag ( )

Definition at line 76 of file RavenHandlerTest.php.

77 {
78 $ravenClient = $this->getRavenClient();
79 $handler = $this->getHandler($ravenClient);
80
81 $tags = array(1, 2, 'foo');
82 $record = $this->getRecord(Logger::INFO, 'test', array('tags' => $tags));
83 $handler->handle($record);
84
85 $this->assertEquals($tags, $ravenClient->lastData['tags']);
86 }
$tags
Definition: croninfo.php:19

References $handler, $tags, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

+ Here is the call graph for this function:

◆ testUserContext()

Monolog\Handler\RavenHandlerTest::testUserContext ( )

Definition at line 116 of file RavenHandlerTest.php.

117 {
118 $ravenClient = $this->getRavenClient();
119 $handler = $this->getHandler($ravenClient);
120
121 $recordWithNoContext = $this->getRecord(Logger::INFO, 'test with default user context');
122 // set user context 'externally'
123
124 $user = array(
125 'id' => '123',
126 'email' => 'test@test.com',
127 );
128
129 $recordWithContext = $this->getRecord(Logger::INFO, 'test', array('user' => $user));
130
131 $ravenClient->user_context(array('id' => 'test_user_id'));
132 // handle context
133 $handler->handle($recordWithContext);
134 $this->assertEquals($user, $ravenClient->lastData['user']);
135
136 // check to see if its reset
137 $handler->handle($recordWithNoContext);
138 $this->assertInternalType('array', $ravenClient->context->user);
139 $this->assertSame('test_user_id', $ravenClient->context->user['id']);
140
141 // handle with null context
142 $ravenClient->user_context(null);
143 $handler->handle($recordWithContext);
144 $this->assertEquals($user, $ravenClient->lastData['user']);
145
146 // check to see if its reset
147 $handler->handle($recordWithNoContext);
148 $this->assertNull($ravenClient->context->user);
149 }
$user
Definition: migrateto20.php:57

References $handler, $user, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

+ Here is the call graph for this function:

◆ testWarning()

Monolog\Handler\RavenHandlerTest::testWarning ( )

Definition at line 64 of file RavenHandlerTest.php.

65 {
66 $ravenClient = $this->getRavenClient();
67 $handler = $this->getHandler($ravenClient);
68
69 $record = $this->getRecord(Logger::WARNING, 'A test warning message');
70 $handler->handle($record);
71
72 $this->assertEquals($ravenClient::WARNING, $ravenClient->lastData['level']);
73 $this->assertContains($record['message'], $ravenClient->lastData['message']);
74 }

References $handler, Monolog\Handler\RavenHandlerTest\getHandler(), Monolog\Handler\RavenHandlerTest\getRavenClient(), Monolog\TestCase\getRecord(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: