ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 with a simple formatting: "<LOG LEVEL> <MESSAGE>". More...
 
 testImplements ()
 
 testLogsAtAllLevels ($level, $message)
 provideLevelsAndMessages More...
 
 provideLevelsAndMessages ()
 
 testThrowsOnInvalidLevel ()
 Psr More...
 
 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 12 of file LoggerInterfaceTest.php.

Member Function Documentation

◆ getLogger()

◆ getLogs()

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

This must return the log messages in order with a simple formatting: "<LOG LEVEL> <MESSAGE>".

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

Returns
string[]

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

+ Here is the caller graph for this function:

◆ provideLevelsAndMessages()

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

Definition at line 49 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.

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

◆ testContextCanContainAnything()

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

Definition at line 91 of file LoggerInterfaceTest.php.

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

92  {
93  $context = array(
94  'bool' => true,
95  'null' => null,
96  'string' => 'Foo',
97  'int' => 0,
98  'float' => 0.5,
99  'nested' => array('with object' => new DummyTest),
100  'object' => new \DateTime,
101  'resource' => fopen('php://memory', 'r'),
102  );
103 
104  $this->getLogger()->warning('Crazy context data', $context);
105  }
+ Here is the call graph for this function:

◆ testContextExceptionKeyCanBeExceptionOrOtherValues()

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

Definition at line 107 of file LoggerInterfaceTest.php.

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

108  {
109  $this->getLogger()->warning('Random message', array('exception' => 'oops'));
110  $this->getLogger()->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail')));
111  }
+ Here is the call graph for this function:

◆ testContextReplacement()

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

Definition at line 72 of file LoggerInterfaceTest.php.

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

73  {
74  $logger = $this->getLogger();
75  $logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar'));
76 
77  $expected = array('info {Message {nothing} Bob Bar a}');
78  $this->assertEquals($expected, $this->getLogs());
79  }
getLogs()
This must return the log messages in order with a simple formatting: "<LOG LEVEL> <MESSAGE>"...
+ Here is the call graph for this function:

◆ testImplements()

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

Definition at line 28 of file LoggerInterfaceTest.php.

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

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

◆ testLogsAtAllLevels()

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

provideLevelsAndMessages

Definition at line 36 of file LoggerInterfaceTest.php.

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

37  {
38  $logger = $this->getLogger();
39  $logger->{$level}($message, array('user' => 'Bob'));
40  $logger->log($level, $message, array('user' => 'Bob'));
41 
42  $expected = array(
43  $level.' message of level '.$level.' with context: Bob',
44  $level.' message of level '.$level.' with context: Bob',
45  );
46  $this->assertEquals($expected, $this->getLogs());
47  }
getLogs()
This must return the log messages in order with a simple formatting: "<LOG LEVEL> <MESSAGE>"...
+ Here is the call graph for this function:

◆ testObjectCastToString()

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

Definition at line 81 of file LoggerInterfaceTest.php.

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

82  {
83  $dummy = $this->getMock('Psr\Log\Test\DummyTest', array('__toString'));
84  $dummy->expects($this->once())
85  ->method('__toString')
86  ->will($this->returnValue('DUMMY'));
87 
88  $this->getLogger()->warning($dummy);
89  }
+ Here is the call graph for this function:

◆ testThrowsOnInvalidLevel()

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

Psr

Definition at line 66 of file LoggerInterfaceTest.php.

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

67  {
68  $logger = $this->getLogger();
69  $logger->log('invalid level', 'Foo');
70  }
+ Here is the call graph for this function:

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