Passed
Push — master ( 7bc6a4...bace86 )
by Dmitriy
06:54 queued 04:27
created

ContainerProxyConfigTest::testGetters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 24
nc 1
nop 0
dl 0
loc 36
rs 9.536
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Unit\Collector;
6
7
use PHPUnit\Framework\TestCase;
8
use Psr\EventDispatcher\EventDispatcherInterface;
9
use Psr\Log\LoggerInterface;
10
use Yiisoft\Yii\Debug\Collector\EventCollector;
11
use Yiisoft\Yii\Debug\Collector\LogCollector;
12
use Yiisoft\Yii\Debug\Collector\ServiceCollector;
13
use Yiisoft\Yii\Debug\Collector\ContainerProxyConfig;
14
use Yiisoft\Yii\Debug\Collector\EventDispatcherInterfaceProxy;
15
use Yiisoft\Yii\Debug\Collector\LoggerInterfaceProxy;
16
17
final class ContainerProxyConfigTest extends TestCase
18
{
19
    public function testImmutability(): void
20
    {
21
        $config = new ContainerProxyConfig();
22
23
        $dispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
24
25
        $this->assertNotSame($config, $config->activate());
26
        $this->assertNotSame($config, $config->withCollector(new ServiceCollector()));
27
        $this->assertNotSame($config, $config->withLogLevel(1));
28
        $this->assertNotSame($config, $config->withProxyCachePath('@tests/runtime'));
29
        $this->assertNotSame(
30
            $config,
31
            $config->withDispatcher(
32
                new EventDispatcherInterfaceProxy($dispatcherMock, new EventCollector())
33
            )
34
        );
35
        $this->assertNotSame(
36
            $config,
37
            $config->withDecoratedServices(
38
                [
39
                    LoggerInterface::class => [LoggerInterfaceProxy::class, LogCollector::class],
40
                ]
41
            )
42
        );
43
    }
44
45
    public function testGetters(): void
46
    {
47
        $dispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
48
        $config = new ContainerProxyConfig(
49
            true,
50
            [
51
                LoggerInterface::class => [LoggerInterfaceProxy::class, LogCollector::class],
52
            ],
53
            $dispatcherMock,
54
            new ServiceCollector(),
55
            '@tests/runtime',
56
            1
57
        );
58
59
        $this->assertTrue($config->getIsActive());
60
        $this->assertInstanceOf(EventDispatcherInterface::class, $config->getDispatcher());
61
        $this->assertInstanceOf(ServiceCollector::class, $config->getCollector());
62
        $this->assertEquals(1, $config->getLogLevel());
63
        $this->assertEquals('@tests/runtime', $config->getProxyCachePath());
64
        $this->assertEquals(
65
            [
66
                LoggerInterface::class => [LoggerInterfaceProxy::class, LogCollector::class],
67
            ],
68
            $config->getDecoratedServices()
69
        );
70
        $this->assertEquals(
71
            [LoggerInterfaceProxy::class, LogCollector::class],
72
            $config->getDecoratedServiceConfig(LoggerInterface::class)
73
        );
74
75
        $this->assertTrue($config->hasCollector());
76
        $this->assertTrue($config->hasDispatcher());
77
        $this->assertTrue($config->hasDecoratedService(LoggerInterface::class));
78
        $this->assertTrue($config->hasDecoratedServiceArrayConfig(LoggerInterface::class));
79
        $this->assertFalse($config->hasDecoratedServiceArrayConfigWithStringKeys(LoggerInterface::class));
80
        $this->assertFalse($config->hasDecoratedServiceCallableConfig(LoggerInterface::class));
81
    }
82
}
83