Passed
Push — master ( 3312bd...c25b5e )
by Kirill
04:35
created

FactoryTest::testDefaultLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Monolog;
13
14
use Monolog\Logger;
15
use PHPUnit\Framework\TestCase;
16
use Psr\Log\LoggerInterface;
17
use Spiral\Boot\BootloadManager;
18
use Spiral\Config\ConfigManager;
19
use Spiral\Config\ConfiguratorInterface;
20
use Spiral\Config\LoaderInterface;
21
use Spiral\Core\Container;
22
use Spiral\Logger\ListenerRegistry;
23
use Spiral\Monolog\Bootloader\MonologBootloader;
24
use Spiral\Monolog\Config\MonologConfig;
25
use Spiral\Monolog\LogFactory;
26
27
class FactoryTest extends TestCase
28
{
29
    public function testDefaultLogger(): void
30
    {
31
        $factory = new LogFactory(new MonologConfig([]), new ListenerRegistry(), new Container());
32
        $logger = $factory->getLogger();
33
34
        $this->assertNotEmpty($logger);
35
        $this->assertSame($logger, $factory->getLogger());
36
        $this->assertSame($logger, $factory->getLogger(LogFactory::DEFAULT));
37
    }
38
39
    public function testInjection(): void
40
    {
41
        $factory = new LogFactory(new MonologConfig([]), new ListenerRegistry(), new Container());
42
        $logger = $factory->getLogger();
43
44
        $container = new Container();
45
        $container->bind(ConfiguratorInterface::class, new ConfigManager(
0 ignored issues
show
Bug introduced by
new Spiral\Config\ConfigManager(new ClassNode()) of type Spiral\Config\ConfigManager is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

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

45
        $container->bind(ConfiguratorInterface::class, /** @scrutinizer ignore-type */ new ConfigManager(
Loading history...
46
            new class() implements LoaderInterface {
47
                public function has(string $section): bool
48
                {
49
                    return false;
50
                }
51
52
                public function load(string $section): array
53
                {
54
                    return [];
55
                }
56
            }
57
        ));
58
        $container->get(BootloadManager::class)->bootload([MonologBootloader::class]);
59
        $container->bind(LogFactory::class, $factory);
0 ignored issues
show
Bug introduced by
$factory of type Spiral\Monolog\LogFactory is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

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

59
        $container->bind(LogFactory::class, /** @scrutinizer ignore-type */ $factory);
Loading history...
60
61
        $this->assertSame($logger, $container->get(Logger::class));
62
        $this->assertSame($logger, $container->get(LoggerInterface::class));
63
    }
64
}
65