34 $this->assertInstanceOf(
'Psr\Log\LoggerInterface', $this->
getLogger());
43 $logger->{$level}(
$message, array(
'user' =>
'Bob'));
44 $logger->log($level,
$message, array(
'user' =>
'Bob'));
47 $level.
' message of level '.$level.
' with context: Bob',
48 $level.
' message of level '.$level.
' with context: Bob',
50 $this->assertEquals($expected, $this->
getLogs());
72 $logger = $this->getLogger();
73 $logger->log(
'invalid level',
'Foo');
78 $logger = $this->getLogger();
79 $logger->info(
'{Message {nothing} {user} {foo.bar} a}', array(
'user' =>
'Bob',
'foo.bar' =>
'Bar'));
81 $expected = array(
'info {Message {nothing} Bob Bar a}');
82 $this->assertEquals($expected, $this->getLogs());
87 if (method_exists($this,
'createPartialMock')) {
88 $dummy = $this->createPartialMock(
'Psr\Log\Test\DummyTest', array(
'__toString'));
90 $dummy = $this->getMock(
'Psr\Log\Test\DummyTest', array(
'__toString'));
92 $dummy->expects($this->
once())
93 ->method(
'__toString')
94 ->will($this->returnValue(
'DUMMY'));
96 $this->getLogger()->warning($dummy);
98 $expected = array(
'warning DUMMY');
99 $this->assertEquals($expected, $this->getLogs());
110 'nested' => array(
'with object' =>
new DummyTest),
111 'object' =>
new \DateTime,
112 'resource' => fopen(
'php://memory',
'r'),
115 $this->getLogger()->warning(
'Crazy context data',
$context);
117 $expected = array(
'warning Crazy context data');
118 $this->assertEquals($expected, $this->getLogs());
123 $logger = $this->getLogger();
124 $logger->warning(
'Random message', array(
'exception' =>
'oops'));
125 $logger->critical(
'Uncaught Exception!', array(
'exception' =>
new \LogicException(
'Fail')));
128 'warning Random message',
129 'critical Uncaught Exception!'
131 $this->assertEquals($expected, $this->getLogs());
An exception for terminatinating execution or to throw for unit testing.
Provides a base test class for ensuring compliance with the LoggerInterface.
testContextExceptionKeyCanBeExceptionOrOtherValues()
getLogs()
This must return the log messages in order.
testLogsAtAllLevels($level, $message)
@dataProvider provideLevelsAndMessages
testContextCanContainAnything()
provideLevelsAndMessages()
testThrowsOnInvalidLevel()
@expectedException \Psr\Log\InvalidArgumentException
Describes a logger instance.
catch(Exception $e) $message
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.