Passed
Pull Request — master (#225)
by Dmitriy
13:44
created

ContainerProxyConfigTest::createServiceCollector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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