Failed Conditions
Pull Request — master (#23)
by Adrien
02:56
created

DbHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 20
dl 0
loc 35
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testHandleWriteIfEnabled() 0 10 1
A testHandleDoesNothingWithoutEnabling() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Log\Handler;
6
7
use DateTimeImmutable;
8
use Ecodev\Felix\Log\Handler\DbHandler;
9
use Ecodev\Felix\Repository\LogRepository;
10
use Monolog\Level;
11
use Monolog\LogRecord;
12
use PHPUnit\Framework\TestCase;
13
14
class DbHandlerTest extends TestCase
15
{
16
    private LogRecord $record;
17
18
    protected function setUp(): void
19
    {
20
        $this->record = new LogRecord(
21
            new DateTimeImmutable(),
22
            '',
23
            Level::Info,
24
            '',
25
        );
26
    }
27
28
    public function testHandleDoesNothingWithoutEnabling(): void
29
    {
30
        $logRepository = $this->createMock(LogRepository::class);
31
        $logRepository->expects(self::never())
32
            ->method('log')
33
            ->with($this->record);
34
35
        $handler = new DbHandler(fn () => $logRepository);
36
        $handler->handle($this->record);
37
    }
38
39
    public function testHandleWriteIfEnabled(): void
40
    {
41
        $logRepository = $this->createMock(LogRepository::class);
42
        $logRepository->expects(self::once())
43
            ->method('log')
44
            ->with($this->record);
45
46
        $handler = new DbHandler(fn () => $logRepository);
47
        $handler->enable();
48
        $handler->handle($this->record);
49
    }
50
}
51