summaryrefslogtreecommitdiff
path: root/tests/Unit/Models/LogEntryTest.php
blob: 0a0efa3ca1859c8b7d37fe13fa7f5e3cdf5fd6ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

namespace Engelsystem\Test\Unit\Models;

use Engelsystem\Models\LogEntry;
use Engelsystem\Test\Unit\HasDatabase;
use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel;

class LogEntryTest extends TestCase
{
    use HasDatabase;

    /**
     * @covers \Engelsystem\Models\LogEntry::filter
     */
    public function testFilter()
    {
        foreach ([
                     'I\'m an info'            => LogLevel::INFO,
                     '*Insert explosion here*' => LogLevel::EMERGENCY,
                     'Tracing along'           => LogLevel::DEBUG,
                     'Oops'                    => LogLevel::ERROR,
                     'It\'s happening'         => LogLevel::INFO,
                     'Something is wrong'      => LogLevel::ERROR,
                     'Ohi'                     => LogLevel::INFO,
                 ] as $message => $level) {
            (new LogEntry(['level' => $level, 'message' => $message]))->save();
        }

        $this->assertCount(7, LogEntry::filter());
        $this->assertCount(3, LogEntry::filter(LogLevel::INFO));
        $this->assertCount(1, LogEntry::filter('Oops'));
    }

    /**
     * Prepare test
     */
    protected function setUp(): void
    {
        $this->initDatabase();
    }
}