2018-08-31 01:55:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Feature\Model;
|
|
|
|
|
|
|
|
use Engelsystem\Models\LogEntry;
|
2022-04-12 22:39:43 +02:00
|
|
|
use Engelsystem\Test\Feature\ApplicationFeatureTest;
|
2018-08-31 01:55:05 +02:00
|
|
|
use Psr\Log\LogLevel;
|
|
|
|
|
2022-04-12 22:39:43 +02:00
|
|
|
class LogEntryTest extends ApplicationFeatureTest
|
2018-08-31 01:55:05 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Models\LogEntry::filter
|
|
|
|
*/
|
|
|
|
public function testFilter(): void
|
|
|
|
{
|
2019-11-10 23:26:23 +01:00
|
|
|
foreach (
|
|
|
|
[
|
|
|
|
'Lorem Ipsum' => LogLevel::INFO,
|
|
|
|
'Some test content' => LogLevel::ERROR,
|
|
|
|
'Foo bar bartz!' => LogLevel::INFO,
|
|
|
|
'Someone did something?' => LogLevel::NOTICE,
|
|
|
|
'This is a Test!' => LogLevel::INFO,
|
|
|
|
'I\'m verbose notice!' => LogLevel::DEBUG,
|
|
|
|
'The newest stuff!!' => LogLevel::ERROR,
|
|
|
|
] as $message => $level
|
|
|
|
) {
|
2018-08-31 01:55:05 +02:00
|
|
|
$entry = new LogEntry(['level' => $level, 'message' => $message]);
|
|
|
|
$entry->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
$model = new LogEntry();
|
|
|
|
|
|
|
|
$return = $model->filter();
|
|
|
|
$this->assertCount(7, $return);
|
|
|
|
|
|
|
|
/** @var LogEntry $first */
|
|
|
|
$first = $return->first();
|
|
|
|
|
|
|
|
$this->assertEquals('The newest stuff!!', $first->message);
|
|
|
|
|
|
|
|
$return = $model->filter(LogLevel::INFO);
|
|
|
|
$this->assertCount(3, $return);
|
|
|
|
|
|
|
|
$return = $model->filter('notice');
|
|
|
|
$this->assertCount(2, $return);
|
|
|
|
|
|
|
|
$return = $model->filter('bartz');
|
|
|
|
$this->assertCount(1, $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
2019-04-24 10:45:00 +02:00
|
|
|
protected function setUp(): void
|
2018-08-31 01:55:05 +02:00
|
|
|
{
|
|
|
|
LogEntry::query()->truncate();
|
|
|
|
}
|
|
|
|
}
|