Passed
Push — extract-store ( ec1a3e...70fc7f )
by Konrad
04:10
created

LoggerPoolTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 34
dl 0
loc 76
rs 10
c 1
b 0
f 1
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetLoggerInvalid() 0 6 1
A testGetEntriesFromAllLoggerInstancesInvalid() 0 9 1
A getSubjectUnderTest() 0 3 1
A testGetLogger() 0 7 1
A testHasEntriesInAnyLoggerInstanceInvalid() 0 9 1
A testGetEntriesFromAllLoggerInstances() 0 13 1
A testCreateNewLogger() 0 3 1
A testHasEntriesInAnyLoggerInstance() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under
5
 * the terms of the GPL-3 license.
6
 *
7
 * (c) Konrad Abicht <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Tests\Unit\Log;
14
15
use Exception;
16
use sweetrdf\InMemoryStoreSqlite\Log\Logger;
17
use sweetrdf\InMemoryStoreSqlite\Log\LoggerPool;
18
use Tests\TestCase;
19
20
class LoggerPoolTest extends TestCase
21
{
22
    private function getSubjectUnderTest(): LoggerPool
23
    {
24
        return new LoggerPool();
25
    }
26
27
    public function testCreateNewLogger()
28
    {
29
        $this->assertEquals(new Logger(), $this->getSubjectUnderTest()->createNewLogger('test'));
30
    }
31
32
    public function testGetLoggerInvalid()
33
    {
34
        $this->expectException(Exception::class);
35
        $this->expectExceptionMessage('Invalid ID given.');
36
37
        $this->getSubjectUnderTest()->getLogger('test');
38
    }
39
40
    public function testGetLogger()
41
    {
42
        $sut = $this->getSubjectUnderTest();
43
        $logger = $sut->createNewLogger('test');
44
45
        $this->assertEquals(new Logger(), $logger);
46
        $this->assertEquals($logger, $sut->getLogger('test'));
47
    }
48
49
    public function testGetEntriesFromAllLoggerInstancesInvalid()
50
    {
51
        $this->expectException(Exception::class);
52
        $this->expectExceptionMessage('Level invalid not set');
53
54
        $sut = $this->getSubjectUnderTest();
55
        $sut->createNewLogger('1');
56
57
        $sut->getEntriesFromAllLoggerInstances('invalid');
58
    }
59
60
    public function testGetEntriesFromAllLoggerInstances()
61
    {
62
        $sut = $this->getSubjectUnderTest();
63
64
        $logger1 = $sut->createNewLogger('1');
65
        $logger1->error('error1');
66
67
        $logger2 = $sut->createNewLogger('2');
68
        $logger2->warning('warning1');
69
70
        $this->assertEquals(2, \count($sut->getEntriesFromAllLoggerInstances()));
71
        $this->assertEquals(1, \count($sut->getEntriesFromAllLoggerInstances('error')));
72
        $this->assertEquals(1, \count($sut->getEntriesFromAllLoggerInstances('warning')));
73
    }
74
75
    public function testHasEntriesInAnyLoggerInstanceInvalid()
76
    {
77
        $this->expectException(Exception::class);
78
        $this->expectExceptionMessage('Level invalid not set');
79
80
        $sut = $this->getSubjectUnderTest();
81
        $sut->createNewLogger('1');
82
83
        $sut->hasEntriesInAnyLoggerInstance('invalid');
84
    }
85
86
    public function testHasEntriesInAnyLoggerInstance()
87
    {
88
        $sut = $this->getSubjectUnderTest();
89
90
        $sut->createNewLogger('1')->error('error1');
91
        $sut->createNewLogger('2')->warning('warning1');
92
93
        $this->assertTrue($sut->hasEntriesInAnyLoggerInstance());
94
        $this->assertTrue($sut->hasEntriesInAnyLoggerInstance('error'));
95
        $this->assertTrue($sut->hasEntriesInAnyLoggerInstance('warning'));
96
    }
97
}
98