Refactoring: Logger test cleanup
This commit is contained in:
parent
c57dfc631c
commit
c35c4ccbf3
|
@ -28,23 +28,6 @@ class EngelsystemLoggerTest extends TestCase
|
||||||
$this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger());
|
$this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider provideLogLevels
|
|
||||||
* @param string $level
|
|
||||||
*/
|
|
||||||
public function testAllLevels($level)
|
|
||||||
{
|
|
||||||
$logger = $this->getLogger();
|
|
||||||
|
|
||||||
LogEntries_clear_all();
|
|
||||||
|
|
||||||
$logger->log($level, 'First log message');
|
|
||||||
$logger->{$level}('Second log message');
|
|
||||||
|
|
||||||
$entries = LogEntries();
|
|
||||||
$this->assertCount(2, $entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
|
@ -62,6 +45,23 @@ class EngelsystemLoggerTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideLogLevels
|
||||||
|
* @param string $level
|
||||||
|
*/
|
||||||
|
public function testAllLevels($level)
|
||||||
|
{
|
||||||
|
$logger = $this->getLogger();
|
||||||
|
|
||||||
|
LogEntries_clear_all();
|
||||||
|
|
||||||
|
$logger->log($level, 'First log message');
|
||||||
|
$logger->{$level}('Second log message');
|
||||||
|
|
||||||
|
$entries = LogEntries();
|
||||||
|
$this->assertCount(2, $entries);
|
||||||
|
}
|
||||||
|
|
||||||
public function testContextReplacement()
|
public function testContextReplacement()
|
||||||
{
|
{
|
||||||
$logger = $this->getLogger();
|
$logger = $this->getLogger();
|
||||||
|
@ -72,21 +72,35 @@ class EngelsystemLoggerTest extends TestCase
|
||||||
$entry = $this->getLastEntry();
|
$entry = $this->getLastEntry();
|
||||||
$this->assertEquals('My username is Foo', $entry['message']);
|
$this->assertEquals('My username is Foo', $entry['message']);
|
||||||
$this->assertEquals(LogLevel::INFO, $entry['level']);
|
$this->assertEquals(LogLevel::INFO, $entry['level']);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (
|
/**
|
||||||
[
|
* @return string[]
|
||||||
['Data and {context}', []],
|
*/
|
||||||
['Data and ', ['context' => null]],
|
public function provideContextReplaceValues()
|
||||||
['Data and {context}', ['context' => new \stdClass()]],
|
{
|
||||||
] as $data
|
return [
|
||||||
) {
|
['Data and {context}', [], 'Data and {context}'],
|
||||||
list($result, $context) = $data;
|
['Data and {context}', ['context' => null], 'Data and '],
|
||||||
|
['Data and {context}', ['context' => new \stdClass()], 'Data and {context}'],
|
||||||
|
['Some user asked: {question}', ['question' => 'Foo?'], 'Some user asked: Foo?'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$logger->log(LogLevel::INFO, 'Data and {context}', $context);
|
/**
|
||||||
|
* @dataProvider provideContextReplaceValues
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param string[] $context
|
||||||
|
* @param string $expected
|
||||||
|
*/
|
||||||
|
public function testContextReplaceValues($message, $context, $expected)
|
||||||
|
{
|
||||||
|
$logger = $this->getLogger();
|
||||||
|
$logger->log(LogLevel::INFO, $message, $context);
|
||||||
|
|
||||||
$entry = $this->getLastEntry();
|
$entry = $this->getLastEntry();
|
||||||
$this->assertEquals($result, $entry['message']);
|
$this->assertEquals($expected, $entry['message']);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContextToString()
|
public function testContextToString()
|
||||||
|
|
Loading…
Reference in New Issue