2019-07-16 02:59:33 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-07-16 02:59:33 +02:00
|
|
|
namespace Engelsystem\Test\Unit\Models;
|
|
|
|
|
|
|
|
use Engelsystem\Models\LogEntry;
|
2023-12-06 17:35:39 +01:00
|
|
|
use Engelsystem\Models\User\User;
|
2019-07-16 02:59:33 +02:00
|
|
|
use Psr\Log\LogLevel;
|
|
|
|
|
2020-05-11 19:57:25 +02:00
|
|
|
class LogEntryTest extends ModelTest
|
2019-07-16 02:59:33 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Models\LogEntry::filter
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testFilter(): void
|
2019-07-16 02:59:33 +02:00
|
|
|
{
|
2023-12-06 17:35:39 +01:00
|
|
|
$user = User::factory()->create();
|
|
|
|
(new LogEntry(['level' => LogLevel::DEBUG, 'message' => 'Some users fault', 'user_id' => $user->id]))->save();
|
2019-11-10 23:26:23 +01:00
|
|
|
foreach (
|
|
|
|
[
|
|
|
|
'I\'m an info' => LogLevel::INFO,
|
|
|
|
'*Insert explosion here*' => LogLevel::EMERGENCY,
|
|
|
|
'Tracing along' => LogLevel::DEBUG,
|
2023-02-05 15:59:56 +01:00
|
|
|
'Oops,no notice given' => LogLevel::NOTICE,
|
2019-11-10 23:26:23 +01:00
|
|
|
'It\'s happening' => LogLevel::INFO,
|
|
|
|
'Something is wrong' => LogLevel::ERROR,
|
|
|
|
'Ohi' => LogLevel::INFO,
|
2023-02-05 15:59:56 +01:00
|
|
|
'I\'m no notice' => LogLevel::CRITICAL,
|
|
|
|
'Just here to warn you!' => LogLevel::WARNING,
|
|
|
|
'The newest stuff!!' => LogLevel::ALERT,
|
2019-11-10 23:26:23 +01:00
|
|
|
] as $message => $level
|
|
|
|
) {
|
2019-07-16 02:59:33 +02:00
|
|
|
(new LogEntry(['level' => $level, 'message' => $message]))->save();
|
|
|
|
}
|
|
|
|
|
2023-12-06 17:35:39 +01:00
|
|
|
$this->assertCount(11, LogEntry::filter());
|
2019-07-16 02:59:33 +02:00
|
|
|
$this->assertCount(3, LogEntry::filter(LogLevel::INFO));
|
|
|
|
$this->assertCount(1, LogEntry::filter('Oops'));
|
2023-12-06 17:35:39 +01:00
|
|
|
$this->assertCount(1, LogEntry::filter(null, $user->id));
|
2023-02-05 15:59:56 +01:00
|
|
|
|
|
|
|
/** @var LogEntry $first */
|
|
|
|
$first = LogEntry::filter()->first();
|
|
|
|
$this->assertEquals('The newest stuff!!', $first->message);
|
|
|
|
|
|
|
|
$return = LogEntry::filter('notice');
|
|
|
|
$this->assertCount(2, $return);
|
|
|
|
|
|
|
|
$return = LogEntry::filter('Ohi');
|
|
|
|
$this->assertCount(1, $return);
|
2019-07-16 02:59:33 +02:00
|
|
|
}
|
|
|
|
}
|