|
|
@ -8,10 +8,12 @@ use Engelsystem\Test\Feature\ApplicationFeatureTest;
|
|
|
|
use Psr\Log\InvalidArgumentException;
|
|
|
|
use Psr\Log\InvalidArgumentException;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use Psr\Log\LogLevel;
|
|
|
|
use Psr\Log\LogLevel;
|
|
|
|
|
|
|
|
use stdClass;
|
|
|
|
|
|
|
|
|
|
|
|
class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Logger\EngelsystemLogger::__construct
|
|
|
|
* @return LoggerInterface
|
|
|
|
* @return LoggerInterface
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getLogger()
|
|
|
|
public function getLogger()
|
|
|
@ -20,6 +22,9 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
return new EngelsystemLogger($logEntry);
|
|
|
|
return new EngelsystemLogger($logEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Logger\EngelsystemLogger::__construct
|
|
|
|
|
|
|
|
*/
|
|
|
|
public function testImplements()
|
|
|
|
public function testImplements()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(LoggerInterface::class, $this->getLogger());
|
|
|
|
$this->assertInstanceOf(LoggerInterface::class, $this->getLogger());
|
|
|
@ -43,6 +48,7 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Models\LogEntry
|
|
|
|
* @dataProvider provideLogLevels
|
|
|
|
* @dataProvider provideLogLevels
|
|
|
|
* @param string $level
|
|
|
|
* @param string $level
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -58,6 +64,9 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
$this->assertCount(2, $entries);
|
|
|
|
$this->assertCount(2, $entries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Logger\EngelsystemLogger::log
|
|
|
|
|
|
|
|
*/
|
|
|
|
public function testContextReplacement()
|
|
|
|
public function testContextReplacement()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogEntry::query()->truncate();
|
|
|
|
LogEntry::query()->truncate();
|
|
|
@ -78,12 +87,13 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
['Data and {context}', [], 'Data and {context}'],
|
|
|
|
['Data and {context}', [], 'Data and {context}'],
|
|
|
|
['Data and {context}', ['context' => null], 'Data and '],
|
|
|
|
['Data and {context}', ['context' => null], 'Data and '],
|
|
|
|
['Data and {context}', ['context' => new \stdClass()], 'Data and {context}'],
|
|
|
|
['Data and {context}', ['context' => new stdClass()], 'Data and {context}'],
|
|
|
|
['Some user asked: {question}', ['question' => 'Foo?'], 'Some user asked: Foo?'],
|
|
|
|
['Some user asked: {question}', ['question' => 'Foo?'], 'Some user asked: Foo?'],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Logger\EngelsystemLogger::log
|
|
|
|
* @dataProvider provideContextReplaceValues
|
|
|
|
* @dataProvider provideContextReplaceValues
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param string $message
|
|
|
@ -99,6 +109,9 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
$this->assertEquals($expected, $entry['message']);
|
|
|
|
$this->assertEquals($expected, $entry['message']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Logger\EngelsystemLogger::log
|
|
|
|
|
|
|
|
*/
|
|
|
|
public function testContextToString()
|
|
|
|
public function testContextToString()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogEntry::query()->truncate();
|
|
|
|
LogEntry::query()->truncate();
|
|
|
@ -119,19 +132,20 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
* @covers \Engelsystem\Logger\EngelsystemLogger::log
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function testThrowExceptionOnInvalidLevel()
|
|
|
|
public function testThrowExceptionOnInvalidLevel()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$logger = $this->getLogger();
|
|
|
|
$logger = $this->getLogger();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$logger->log('This log level should never be defined', 'Some message');
|
|
|
|
$logger->log('This log level should never be defined', 'Some message');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getLastEntry()
|
|
|
|
protected function getLastEntry()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$entries = LogEntry::all();
|
|
|
|
$entries = LogEntry::all();
|
|
|
|
$entry = $entries->last();
|
|
|
|
$entry = $entries->last();
|
|
|
@ -139,7 +153,10 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
|
|
|
|
return $entry;
|
|
|
|
return $entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Cleanup
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogEntry::query()->truncate();
|
|
|
|
LogEntry::query()->truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|