LoggerTest.php$0 ➔ getTraitLogger()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\PHPCommandBus\Tests\Unit\Traits;
6
7
use Psr\Log;
8
use RemotelyLiving\PHPCommandBus\Tests;
9
use RemotelyLiving\PHPCommandBus\Traits;
10
11
class LoggerTest extends Tests\Unit\AbstractTestCase
12
{
13
    private Log\Test\TestLogger $testLogger;
14
15
    private Log\LoggerAwareInterface $loggableClass;
16
17
    protected function setUp(): void
18
    {
19
        $this->testLogger = $this->createTestLogger();
20
        $this->loggableClass = new class implements Log\LoggerAwareInterface {
21
            use Traits\Logger;
22
23
            public function getTraitLogger(): Log\LoggerInterface
24
            {
25
                return $this->getLogger();
26
            }
27
        };
28
    }
29
30
    public function testDefaultLoggerIsNullLogger(): void
31
    {
32
        $this->assertInstanceOf(Log\NullLogger::class, $this->loggableClass->getTraitLogger());
0 ignored issues
show
Bug introduced by
The method getTraitLogger() does not exist on Psr\Log\LoggerAwareInterface. It seems like you code against a sub-type of Psr\Log\LoggerAwareInterface such as anonymous//tests/Unit/Traits/LoggerTest.php$0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $this->assertInstanceOf(Log\NullLogger::class, $this->loggableClass->/** @scrutinizer ignore-call */ getTraitLogger());
Loading history...
33
    }
34
35
    public function testSetsLogger(): void
36
    {
37
        $this->loggableClass->setLogger($this->testLogger);
38
        $this->assertInstanceOf(Log\Test\TestLogger::class, $this->loggableClass->getTraitLogger());
39
    }
40
41
    public function testLogs(): void
42
    {
43
        $this->loggableClass->setLogger($this->testLogger);
44
        $this->loggableClass->getTraitLogger()->log('critical', 'the message', ['the' => 'context']);
45
46
        $this->assertSame([
47
            'level' => 'critical',
48
            'message' => 'the message',
49
            'context' => ['the' => 'context'],
50
        ], $this->testLogger->records[0]);
51
    }
52
}
53