summaryrefslogtreecommitdiff
path: root/tests/Feature/Model/LogEntryTest.php
blob: 7fad823235f6a9a636c5eb70d87c225478acb00d (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
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace Engelsystem\Test\Feature\Model;

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

class LogEntryTest extends TestCase
{
    /**
     * @covers \Engelsystem\Models\LogEntry::filter
     */
    public function testFilter()
    {
        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) {
            $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.
     */
    protected function setUp(): void
    {
        LogEntry::query()->truncate();
    }
}