Passed
Pull Request — master (#444)
by Alejandro
08:41 queued 05:16
created

LoggerFactoryTest::serviceIsCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Logger;
5
6
use Monolog\Logger;
7
use PHPUnit\Framework\TestCase;
8
use Psr\Log\LoggerInterface;
9
use Shlinkio\Shlink\Common\Logger\LoggerFactory;
10
use Zend\ServiceManager\ServiceManager;
11
12
class LoggerFactoryTest extends TestCase
13
{
14
    /** @var LoggerFactory */
15
    private $factory;
16
17
    public function setUp(): void
18
    {
19
        $this->factory = new LoggerFactory();
20
    }
21
22
    /** @test */
23
    public function serviceIsCreated()
24
    {
25
        /** @var Logger $instance */
26
        $instance = $this->factory->__invoke(new ServiceManager(), '');
27
        $this->assertInstanceOf(LoggerInterface::class, $instance);
28
        $this->assertEquals('Logger', $instance->getName());
29
    }
30
31
    /** @test */
32
    public function nameIsSetFromOptions()
33
    {
34
        /** @var Logger $instance */
35
        $instance = $this->factory->__invoke(new ServiceManager(), '', ['logger_name' => 'Foo']);
36
        $this->assertInstanceOf(LoggerInterface::class, $instance);
37
        $this->assertEquals('Foo', $instance->getName());
38
    }
39
40
    /** @test */
41
    public function serviceNameOverwritesOptionsLoggerName()
42
    {
43
        /** @var Logger $instance */
44
        $instance = $this->factory->__invoke(new ServiceManager(), 'Logger_Shlink', ['logger_name' => 'Foo']);
45
        $this->assertInstanceOf(LoggerInterface::class, $instance);
46
        $this->assertEquals('Shlink', $instance->getName());
47
    }
48
}
49