3 namespace Psr\Log\Test;
30 abstract public function getLogs();
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());
53 public function provideLevelsAndMessages()
70 public function testThrowsOnInvalidLevel()
72 $logger = $this->getLogger();
73 $logger->log(
'invalid level',
'Foo');
76 public function testContextReplacement()
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());
85 public function testObjectCastToString()
87 $dummy = $this->getMock(
'Psr\Log\Test\DummyTest', array(
'__toString'));
88 $dummy->expects($this->once())
89 ->method(
'__toString')
90 ->will($this->returnValue(
'DUMMY'));
92 $this->getLogger()->warning($dummy);
94 $expected = array(
'warning DUMMY');
95 $this->assertEquals($expected, $this->getLogs());
98 public function testContextCanContainAnything()
106 'nested' => array(
'with object' =>
new DummyTest),
107 'object' =>
new \DateTime,
108 'resource' => fopen(
'php://memory',
'r'),
111 $this->getLogger()->warning(
'Crazy context data', $context);
113 $expected = array(
'warning Crazy context data');
114 $this->assertEquals($expected, $this->getLogs());
117 public function testContextExceptionKeyCanBeExceptionOrOtherValues()
119 $logger = $this->getLogger();
120 $logger->warning(
'Random message', array(
'exception' =>
'oops'));
121 $logger->critical(
'Uncaught Exception!', array(
'exception' =>
new \LogicException(
'Fail')));
124 'warning Random message',
125 'critical Uncaught Exception!'
127 $this->assertEquals($expected, $this->getLogs());