Completed
Push — master ( a37b1d...a8a96a )
by Tobias
22:51
created

DataCollectorCompilerPassTest::testWithLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of php-cache\cache-bundle package.
5
 *
6
 * (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\CacheBundle\Tests\Unit\DependencyInjection;
13
14
use Cache\CacheBundle\DependencyInjection\Compiler\DataCollectorCompilerPass;
15
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Definition;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
class DataCollectorCompilerPassTest extends AbstractCompilerPassTestCase
21
{
22
    protected function registerCompilerPass(ContainerBuilder $container)
23
    {
24
        $container->addCompilerPass(new DataCollectorCompilerPass());
25
    }
26
27
    public function testWithLogger()
28
    {
29
        $collector = new Definition();
30
        $this->setDefinition('cache.data_collector', $collector);
31
32
        $this->setParameter('cache.logging', ['logger' => 'foo_logger', 'level' => 'bar']);
33
        $this->compile();
34
35
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
36
            'cache.recorder_factory',
37
            0,
38
            new Reference('foo_logger')
39
        );
40
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
41
            'cache.recorder_factory',
42
            1,
43
            'bar'
44
        );
45
    }
46
47
    public function testFactory()
48
    {
49
        $collector = new Definition();
50
        $this->setDefinition('cache.data_collector', $collector);
51
52
        $collectedService = new Definition();
53
        $collectedService->addTag('cache.provider');
54
        $this->setDefinition('collected_pool', $collectedService);
55
56
        $this->compile();
57
58
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
59
            'cache.data_collector',
60
            'addInstance',
61
            [
62
                'collected_pool',
63
                new Reference('collected_pool'),
64
            ]
65
        );
66
67
        $this->assertContainerBuilderHasService('collected_pool.inner');
68
        $this->assertContainerBuilderHasServiceDefinitionWithTag('collected_pool', 'cache.provider');
69
    }
70
}
71