Failed Conditions
Pull Request — master (#11)
by Adrien
15:48 queued 12:33
created

LoggerFactoryTest::testWithMailWriter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 10
c 1
b 0
f 0
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;
1 ignored issue
show
Bug introduced by
The type Ecodev\Felix\Log\Writer\Db was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 => fn () => 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

32
                Db::class => fn () => self::/** @scrutinizer ignore-call */ createMock(Db::class),
Loading history...
33
                Mail::class => fn () => 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

33
                Mail::class => fn () => self::/** @scrutinizer ignore-call */ createMock(Mail::class),
Loading history...
34
            ],
35
        ]);
36
37
        $factory = new LoggerFactory();
38
        $actual = $factory($container, '');
39
        self::assertInstanceOf(Logger::class, $actual);
40
        self::assertCount(3, $actual->getWriters());
41
    }
42
43
    public function testWithoutMailWriter(): void
44
    {
45
        $container = new ServiceManager([
46
            'factories' => [
47
                Db::class => fn () => 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

47
                Db::class => fn () => self::/** @scrutinizer ignore-call */ createMock(Db::class),
Loading history...
48
                Mail::class => fn () => null,
49
            ],
50
        ]);
51
52
        $factory = new LoggerFactory();
53
        $actual = $factory($container, '');
54
        self::assertInstanceOf(Logger::class, $actual);
55
        self::assertCount(2, $actual->getWriters());
56
    }
57
}
58