ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Psr\Log\Test\LoggerInterfaceTest Class Reference

Provides a base test class for ensuring compliance with the LoggerInterface. More...

+ Inheritance diagram for Psr\Log\Test\LoggerInterfaceTest:
+ Collaboration diagram for Psr\Log\Test\LoggerInterfaceTest:

Public Member Functions

 getLogger ()
 
 getLogs ()
 This must return the log messages in order. More...
 
 testImplements ()
 
 testLogsAtAllLevels ($level, $message)
 provideLevelsAndMessages More...
 
 provideLevelsAndMessages ()
 
 testThrowsOnInvalidLevel ()
 
 testContextReplacement ()
 
 testObjectCastToString ()
 
 testContextCanContainAnything ()
 
 testContextExceptionKeyCanBeExceptionOrOtherValues ()
 

Detailed Description

Provides a base test class for ensuring compliance with the LoggerInterface.

Implementors can extend the class and implement abstract methods to run this as part of their test suite.

Definition at line 14 of file LoggerInterfaceTest.php.

Member Function Documentation

◆ getLogger()

◆ getLogs()

Psr\Log\Test\LoggerInterfaceTest::getLogs ( )
abstract

This must return the log messages in order.

The simple formatting of the messages is: "<LOG LEVEL> <MESSAGE>".

Example ->error('Foo') would yield "error Foo".

Returns
string[]

Referenced by Psr\Log\Test\LoggerInterfaceTest\testContextCanContainAnything(), Psr\Log\Test\LoggerInterfaceTest\testContextExceptionKeyCanBeExceptionOrOtherValues(), Psr\Log\Test\LoggerInterfaceTest\testContextReplacement(), Psr\Log\Test\LoggerInterfaceTest\testLogsAtAllLevels(), and Psr\Log\Test\LoggerInterfaceTest\testObjectCastToString().

+ Here is the caller graph for this function:

◆ provideLevelsAndMessages()

Psr\Log\Test\LoggerInterfaceTest::provideLevelsAndMessages ( )

Definition at line 53 of file LoggerInterfaceTest.php.

References Psr\Log\LogLevel\ALERT, Psr\Log\LogLevel\CRITICAL, Psr\Log\LogLevel\DEBUG, Psr\Log\LogLevel\EMERGENCY, Psr\Log\LogLevel\ERROR, Psr\Log\LogLevel\INFO, Psr\Log\LogLevel\NOTICE, and Psr\Log\LogLevel\WARNING.

54  {
55  return array(
56  LogLevel::EMERGENCY => array(LogLevel::EMERGENCY, 'message of level emergency with context: {user}'),
57  LogLevel::ALERT => array(LogLevel::ALERT, 'message of level alert with context: {user}'),
58  LogLevel::CRITICAL => array(LogLevel::CRITICAL, 'message of level critical with context: {user}'),
59  LogLevel::ERROR => array(LogLevel::ERROR, 'message of level error with context: {user}'),
60  LogLevel::WARNING => array(LogLevel::WARNING, 'message of level warning with context: {user}'),
61  LogLevel::NOTICE => array(LogLevel::NOTICE, 'message of level notice with context: {user}'),
62  LogLevel::INFO => array(LogLevel::INFO, 'message of level info with context: {user}'),
63  LogLevel::DEBUG => array(LogLevel::DEBUG, 'message of level debug with context: {user}'),
64  );
65  }

◆ testContextCanContainAnything()

Psr\Log\Test\LoggerInterfaceTest::testContextCanContainAnything ( )

Definition at line 102 of file LoggerInterfaceTest.php.

References $context, Psr\Log\Test\LoggerInterfaceTest\getLogger(), and Psr\Log\Test\LoggerInterfaceTest\getLogs().

103  {
104  $context = array(
105  'bool' => true,
106  'null' => null,
107  'string' => 'Foo',
108  'int' => 0,
109  'float' => 0.5,
110  'nested' => array('with object' => new DummyTest),
111  'object' => new \DateTime,
112  'resource' => fopen('php://memory', 'r'),
113  );
114 
115  $this->getLogger()->warning('Crazy context data', $context);
116 
117  $expected = array('warning Crazy context data');
118  $this->assertEquals($expected, $this->getLogs());
119  }
$context
Definition: webdav.php:25
getLogs()
This must return the log messages in order.
+ Here is the call graph for this function:

◆ testContextExceptionKeyCanBeExceptionOrOtherValues()

Psr\Log\Test\LoggerInterfaceTest::testContextExceptionKeyCanBeExceptionOrOtherValues ( )

Definition at line 121 of file LoggerInterfaceTest.php.

References Psr\Log\Test\LoggerInterfaceTest\getLogger(), and Psr\Log\Test\LoggerInterfaceTest\getLogs().

122  {
123  $logger = $this->getLogger();
124  $logger->warning('Random message', array('exception' => 'oops'));
125  $logger->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail')));
126 
127  $expected = array(
128  'warning Random message',
129  'critical Uncaught Exception!'
130  );
131  $this->assertEquals($expected, $this->getLogs());
132  }
getLogs()
This must return the log messages in order.
+ Here is the call graph for this function:

◆ testContextReplacement()

Psr\Log\Test\LoggerInterfaceTest::testContextReplacement ( )

Definition at line 76 of file LoggerInterfaceTest.php.

References Psr\Log\Test\LoggerInterfaceTest\getLogger(), and Psr\Log\Test\LoggerInterfaceTest\getLogs().

77  {
78  $logger = $this->getLogger();
79  $logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar'));
80 
81  $expected = array('info {Message {nothing} Bob Bar a}');
82  $this->assertEquals($expected, $this->getLogs());
83  }
getLogs()
This must return the log messages in order.
+ Here is the call graph for this function:

◆ testImplements()

Psr\Log\Test\LoggerInterfaceTest::testImplements ( )

Definition at line 32 of file LoggerInterfaceTest.php.

References Psr\Log\Test\LoggerInterfaceTest\getLogger().

33  {
34  $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger());
35  }
+ Here is the call graph for this function:

◆ testLogsAtAllLevels()

Psr\Log\Test\LoggerInterfaceTest::testLogsAtAllLevels (   $level,
  $message 
)

provideLevelsAndMessages

Definition at line 40 of file LoggerInterfaceTest.php.

References $message, Psr\Log\Test\LoggerInterfaceTest\getLogger(), and Psr\Log\Test\LoggerInterfaceTest\getLogs().

41  {
42  $logger = $this->getLogger();
43  $logger->{$level}($message, array('user' => 'Bob'));
44  $logger->log($level, $message, array('user' => 'Bob'));
45 
46  $expected = array(
47  $level.' message of level '.$level.' with context: Bob',
48  $level.' message of level '.$level.' with context: Bob',
49  );
50  $this->assertEquals($expected, $this->getLogs());
51  }
catch(Exception $e) $message
getLogs()
This must return the log messages in order.
+ Here is the call graph for this function:

◆ testObjectCastToString()

Psr\Log\Test\LoggerInterfaceTest::testObjectCastToString ( )

Definition at line 85 of file LoggerInterfaceTest.php.

References Psr\Log\Test\LoggerInterfaceTest\getLogger(), Psr\Log\Test\LoggerInterfaceTest\getLogs(), and Sabre\Event\once().

86  {
87  if (method_exists($this, 'createPartialMock')) {
88  $dummy = $this->createPartialMock('Psr\Log\Test\DummyTest', array('__toString'));
89  } else {
90  $dummy = $this->getMock('Psr\Log\Test\DummyTest', array('__toString'));
91  }
92  $dummy->expects($this->once())
93  ->method('__toString')
94  ->will($this->returnValue('DUMMY'));
95 
96  $this->getLogger()->warning($dummy);
97 
98  $expected = array('warning DUMMY');
99  $this->assertEquals($expected, $this->getLogs());
100  }
getLogs()
This must return the log messages in order.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testThrowsOnInvalidLevel()

Psr\Log\Test\LoggerInterfaceTest::testThrowsOnInvalidLevel ( )

Definition at line 70 of file LoggerInterfaceTest.php.

References Psr\Log\Test\LoggerInterfaceTest\getLogger().

71  {
72  $logger = $this->getLogger();
73  $logger->log('invalid level', 'Foo');
74  }
+ Here is the call graph for this function:

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