Passed
Push — master ( 89f24e...8c4dad )
by Sylvain
08:05
created

LoggerFactoryTest::testWithMailWriter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Log;
6
7
use Ecodev\Felix\Log\LoggerFactory;
8
use Ecodev\Felix\Log\Writer\Db;
9
use Ecodev\Felix\Log\Writer\Mail;
10
use Laminas\Log\Logger;
11
use Laminas\ServiceManager\ServiceManager;
12
use PHPUnit\Framework\TestCase;
13
14
class LoggerFactoryTest extends TestCase
15
{
16
    protected function setUp(): void
17
    {
18
        @mkdir('logs');
19
    }
20
21
    protected function tearDown(): void
22
    {
23
        Logger::unregisterErrorHandler();
24
        Logger::unregisterExceptionHandler();
25
        shell_exec('rm -rf logs/');
26
    }
27
28
    public function testWithMailWriter(): void
29
    {
30
        $container = new ServiceManager([
31
            'factories' => [
32
                Db::class => function () {
33
                    return self::createMock(Db::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::createMock() is not static, but was called statically. ( Ignorable by Annotation )

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

33
                    return self::/** @scrutinizer ignore-call */ createMock(Db::class);
Loading history...
34
                },
35
                Mail::class => function () {
36
                    return self::createMock(Mail::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::createMock() is not static, but was called statically. ( Ignorable by Annotation )

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

36
                    return self::/** @scrutinizer ignore-call */ createMock(Mail::class);
Loading history...
37
                },
38
            ],
39
        ]);
40
41
        $factory = new LoggerFactory();
42
        $actual = $factory($container, '');
43
        self::assertInstanceOf(Logger::class, $actual);
44
        self::assertCount(3, $actual->getWriters());
45
    }
46
47
    public function testWithoutMailWriter(): void
48
    {
49
        $container = new ServiceManager([
50
            'factories' => [
51
                Db::class => function () {
52
                    return self::createMock(Db::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::createMock() is not static, but was called statically. ( Ignorable by Annotation )

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

52
                    return self::/** @scrutinizer ignore-call */ createMock(Db::class);
Loading history...
53
                },
54
                Mail::class => function () {
55
                    return null;
56
                },
57
            ],
58
        ]);
59
60
        $factory = new LoggerFactory();
61
        $actual = $factory($container, '');
62
        self::assertInstanceOf(Logger::class, $actual);
63
        self::assertCount(2, $actual->getWriters());
64
    }
65
}
66