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

TraitTest::testNoScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
eloc 3
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\NullLogger;
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\Core\ContainerScope;
23
use Spiral\Logger\ListenerRegistry;
24
use Spiral\Logger\ListenerRegistryInterface;
25
use Spiral\Logger\Traits\LoggerTrait;
26
use Spiral\Monolog\Bootloader\MonologBootloader;
27
use Spiral\Monolog\Config\MonologConfig;
28
29
class TraitTest extends TestCase
30
{
31
    use LoggerTrait;
32
33
    public function setUp(): void
34
    {
35
        $this->logger = null;
36
    }
37
38
    public function testNoScope(): void
39
    {
40
        $logger = $this->getLogger();
41
        $this->assertInstanceOf(NullLogger::class, $this->getLogger());
42
        $this->assertSame($logger, $this->getLogger());
43
    }
44
45
    public function testSetLogger(): void
46
    {
47
        $logger = new NullLogger();
48
        $this->setLogger($logger);
49
        $this->assertSame($logger, $this->getLogger());
50
    }
51
52
    public function testScope(): void
53
    {
54
        $container = new Container();
55
        $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

55
        $container->bind(ConfiguratorInterface::class, /** @scrutinizer ignore-type */ new ConfigManager(
Loading history...
56
            new class() implements LoaderInterface {
57
                public function has(string $section): bool
58
                {
59
                    return false;
60
                }
61
62
                public function load(string $section): array
63
                {
64
                    return [];
65
                }
66
            }
67
        ));
68
        $container->get(BootloadManager::class)->bootload([MonologBootloader::class]);
69
        $container->bind(MonologConfig::class, new MonologConfig());
0 ignored issues
show
Bug introduced by
new Spiral\Monolog\Config\MonologConfig() of type Spiral\Monolog\Config\MonologConfig 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

69
        $container->bind(MonologConfig::class, /** @scrutinizer ignore-type */ new MonologConfig());
Loading history...
70
        $container->bind(ListenerRegistryInterface::class, new ListenerRegistry());
0 ignored issues
show
Bug introduced by
new Spiral\Logger\ListenerRegistry() of type Spiral\Logger\ListenerRegistry 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

70
        $container->bind(ListenerRegistryInterface::class, /** @scrutinizer ignore-type */ new ListenerRegistry());
Loading history...
71
72
        ContainerScope::runScope($container, function (): void {
73
            $this->assertInstanceOf(Logger::class, $this->getLogger());
74
            $this->assertSame(self::class, $this->getLogger()->getName());
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Psr\Log\LoggerInterface. It seems like you code against a sub-type of Psr\Log\LoggerInterface such as Monolog\Logger or Psr\Log\Test\TestLogger. ( Ignorable by Annotation )

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

74
            $this->assertSame(self::class, $this->getLogger()->/** @scrutinizer ignore-call */ getName());
Loading history...
75
        });
76
    }
77
}
78