24 $logger =
new Logger(
'foo');
25 $this->assertEquals(
'foo', $logger->getName());
33 $this->assertEquals(
'ERROR', Logger::getLevelName(Logger::ERROR));
41 $this->assertEquals(Logger::toMonologLevel(
'debug'), 100);
42 $this->assertEquals(Logger::toMonologLevel(
'info'), 200);
43 $this->assertEquals(Logger::toMonologLevel(
'notice'), 250);
44 $this->assertEquals(Logger::toMonologLevel(
'warning'), 300);
45 $this->assertEquals(Logger::toMonologLevel(
'error'), 400);
46 $this->assertEquals(Logger::toMonologLevel(
'critical'), 500);
47 $this->assertEquals(Logger::toMonologLevel(
'alert'), 550);
48 $this->assertEquals(Logger::toMonologLevel(
'emergency'), 600);
57 Logger::getLevelName(5);
65 $logger =
new Logger(
'foo');
67 $logger->pushHandler($handler);
68 $logger->addWarning(
'test');
70 $this->assertEquals(
'foo', $record[
'channel']);
78 $logger =
new Logger(__METHOD__);
80 $handler = $this->getMock(
'Monolog\Handler\NullHandler', array(
'handle'));
81 $handler->expects($this->once())
83 $logger->pushHandler($handler);
85 $this->assertTrue($logger->addWarning(
'test'));
93 $logger =
new Logger(__METHOD__);
95 $handler = $this->getMock(
'Monolog\Handler\NullHandler', array(
'handle'), array(Logger::ERROR));
96 $handler->expects($this->never())
98 $logger->pushHandler($handler);
100 $this->assertFalse($logger->addWarning(
'test'));
107 $logger =
new Logger(__METHOD__, array($handler1, $handler2));
109 $this->assertEquals($handler1, $logger->popHandler());
110 $this->assertEquals($handler2, $logger->popHandler());
117 $logger =
new Logger(__METHOD__, array(), array($processor1, $processor2));
119 $this->assertEquals($processor1, $logger->popProcessor());
120 $this->assertEquals($processor2, $logger->popProcessor());
130 $logger =
new Logger(__METHOD__);
134 $logger->pushHandler($handler1);
135 $logger->pushHandler($handler2);
137 $this->assertEquals($handler2, $logger->popHandler());
138 $this->assertEquals($handler1, $logger->popHandler());
139 $logger->popHandler();
149 $logger =
new Logger(__METHOD__);
153 $logger->pushProcessor($processor1);
154 $logger->pushProcessor($processor2);
156 $this->assertEquals($processor2, $logger->popProcessor());
157 $this->assertEquals($processor1, $logger->popProcessor());
158 $logger->popProcessor();
167 $logger =
new Logger(__METHOD__);
169 $logger->pushProcessor(
new \stdClass());
177 $logger =
new Logger(__METHOD__);
179 $logger->pushHandler($handler);
181 $record[
'extra'][
'win'] =
true;
185 $logger->addError(
'test');
186 list($record) = $handler->getRecords();
187 $this->assertTrue($record[
'extra'][
'win']);
195 $logger =
new Logger(__METHOD__);
196 $handler = $this->getMock(
'Monolog\Handler\HandlerInterface');
197 $handler->expects($this->any())
198 ->method(
'isHandling')
199 ->will($this->returnValue(
true))
201 $handler->expects($this->any())
203 ->will($this->returnValue(
true))
205 $logger->pushHandler($handler);
207 $processor = $this->getMockBuilder(
'Monolog\Processor\WebProcessor')
208 ->disableOriginalConstructor()
209 ->setMethods(array(
'__invoke'))
212 $processor->expects($this->once())
214 ->will($this->returnArgument(0))
216 $logger->pushProcessor($processor);
218 $logger->addError(
'test');
226 $logger =
new Logger(__METHOD__);
227 $handler = $this->getMock(
'Monolog\Handler\HandlerInterface');
228 $handler->expects($this->once())
229 ->method(
'isHandling')
230 ->will($this->returnValue(
false))
232 $logger->pushHandler($handler);
234 $logger->pushProcessor(
function ($record) use ($that) {
235 $that->fail(
'The processor should not be called');
237 $logger->addAlert(
'test');
245 $logger =
new Logger(__METHOD__);
247 $handler1 = $this->getMock(
'Monolog\Handler\HandlerInterface');
248 $handler1->expects($this->never())
249 ->method(
'isHandling')
250 ->will($this->returnValue(
false))
252 $handler1->expects($this->once())
254 ->will($this->returnValue(
false))
256 $logger->pushHandler($handler1);
258 $handler2 = $this->getMock(
'Monolog\Handler\HandlerInterface');
259 $handler2->expects($this->once())
260 ->method(
'isHandling')
261 ->will($this->returnValue(
true))
263 $handler2->expects($this->once())
265 ->will($this->returnValue(
false))
267 $logger->pushHandler($handler2);
269 $handler3 = $this->getMock(
'Monolog\Handler\HandlerInterface');
270 $handler3->expects($this->once())
271 ->method(
'isHandling')
272 ->will($this->returnValue(
false))
274 $handler3->expects($this->never())
277 $logger->pushHandler($handler3);
279 $logger->debug(
'test');
287 $logger =
new Logger(__METHOD__);
289 $handler1 = $this->getMock(
'Monolog\Handler\HandlerInterface');
290 $handler1->expects($this->any())
291 ->method(
'isHandling')
292 ->will($this->returnValue(
true))
294 $handler1->expects($this->once())
296 ->will($this->returnValue(
false))
298 $logger->pushHandler($handler1);
300 $handler2 = $this->getMock(
'Monolog\Handler\HandlerInterface');
301 $handler2->expects($this->any())
302 ->method(
'isHandling')
303 ->will($this->returnValue(
true))
305 $handler2->expects($this->once())
307 ->will($this->returnValue(
false))
309 $logger->pushHandler($handler2);
311 $logger->debug(
'test');
319 $logger =
new Logger(__METHOD__);
321 $handler1 = $this->getMock(
'Monolog\Handler\HandlerInterface');
322 $handler1->expects($this->any())
323 ->method(
'isHandling')
324 ->will($this->returnValue(
true))
326 $handler1->expects($this->never())
329 $logger->pushHandler($handler1);
331 $handler2 = $this->getMock(
'Monolog\Handler\HandlerInterface');
332 $handler2->expects($this->any())
333 ->method(
'isHandling')
334 ->will($this->returnValue(
true))
336 $handler2->expects($this->once())
338 ->will($this->returnValue(
true))
340 $logger->pushHandler($handler2);
342 $logger->debug(
'test');
350 $logger =
new Logger(__METHOD__);
352 $handler1 = $this->getMock(
'Monolog\Handler\HandlerInterface');
353 $handler1->expects($this->any())
354 ->method(
'isHandling')
355 ->will($this->returnValue(
false))
358 $logger->pushHandler($handler1);
361 $handler2 = $this->getMock(
'Monolog\Handler\HandlerInterface');
362 $handler2->expects($this->any())
363 ->method(
'isHandling')
364 ->will($this->returnValue(
true))
367 $logger->pushHandler($handler2);
392 $logger =
new Logger(
'foo');
394 $logger->pushHandler($handler);
395 $logger->{$method}(
'test');
397 $this->assertEquals($expectedLevel, $record[
'level']);
405 array(
'addInfo', Logger::INFO),
406 array(
'addNotice', Logger::NOTICE),
407 array(
'addWarning', Logger::WARNING),
408 array(
'addError', Logger::ERROR),
409 array(
'addCritical', Logger::CRITICAL),
410 array(
'addAlert', Logger::ALERT),
411 array(
'addEmergency', Logger::EMERGENCY),
415 array(
'info', Logger::INFO),
416 array(
'notice', Logger::NOTICE),
417 array(
'warn', Logger::WARNING),
418 array(
'err', Logger::ERROR),
419 array(
'crit', Logger::CRITICAL),
420 array(
'alert', Logger::ALERT),
421 array(
'emerg', Logger::EMERGENCY),
431 Logger::setTimezone(
$tz);
432 $logger =
new Logger(
'foo');
434 $logger->pushHandler($handler);
435 $logger->info(
'test');
437 $this->assertEquals(
$tz, $record[
'datetime']->getTimezone());
443 function (
$tz) {
return array(
new \DateTimeZone(
$tz)); },
444 \DateTimeZone::listIdentifiers()
testLogNotHandled()
Monolog::addRecord
testProcessorsAreExecuted()
Monolog::addRecord
Injects url/method and remote IP of the current web request in all records.
testBubblingWhenTheHandlerReturnsFalse()
Monolog::addRecord
testConvertPSR3ToMonologLevel()
Monolog::toMonologLevel
testIsHandling()
Monolog::isHandling
testChannel()
Monolog::__construct
testSetTimezone($tz)
setTimezoneProvider Monolog::setTimezone
testGetName()
Monolog::getName
testLog()
Monolog::addRecord
testProcessorsNotCalledWhenNotHandled()
Monolog::addRecord
testGetLevelNameThrows()
Monolog::getLevelName InvalidArgumentException
testHandlersNotCalledBeforeFirstHandling()
Monolog::addRecord
testProcessorsAreCalledOnlyOnce()
Monolog::addRecord
testPushProcessorWithNonCallable()
Monolog::pushProcessor InvalidArgumentException
testLogMethods($method, $expectedLevel)
logMethodProvider Monolog::addDebug Monolog::addInfo Monolog::addNotice Monolog::addWarning Mono...
Used for testing purposes.
testPushPopHandler()
Monolog::pushHandler Monolog::popHandler LogicException
testGetLevelName()
Monolog::getLevelName
testNotBubblingWhenTheHandlerReturnsTrue()
Monolog::addRecord
pushProcessor($callback)
{Adds a processor in the stack.self}
testPushPopProcessor()
Monolog::pushProcessor Monolog::popProcessor LogicException