Completed
Push — master ( 2db2f3...bf6a9d )
by Jérémy
9s
created

testProcessChannelExcludeChannels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\NewRelicBundle\Tests\DependencyInjection\Compiler;
15
16
use Ekino\NewRelicBundle\DependencyInjection\Compiler\MonologHandlerPass;
17
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
class MonologHandlerPassTest extends AbstractCompilerPassTestCase
22
{
23
    protected function registerCompilerPass(ContainerBuilder $container)
24
    {
25
        $container->addCompilerPass(new MonologHandlerPass());
26
    }
27
28
    public function testProcessChannel()
29
    {
30
        $this->container->setParameter('ekino.new_relic.monolog.channels', ['type' => 'inclusive', 'elements' => ['app', 'foo']]);
31
        $this->registerService('monolog.logger', \Monolog\Logger::class)->setArgument(0, 'app');
32
        $this->registerService('monolog.logger.foo', \Monolog\Logger::class)->setArgument(0, 'foo');
33
34
        $this->compile();
35
36
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('monolog.logger', 'pushHandler', [new Reference('ekino.new_relic.logs_handler')]);
37
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('monolog.logger.foo', 'pushHandler', [new Reference('ekino.new_relic.logs_handler')]);
38
    }
39
40
    public function testProcessChannelAllChannels()
41
    {
42
        $this->container->setParameter('ekino.new_relic.monolog.channels', null);
43
        $this->registerService('monolog.logger', \Monolog\Logger::class)->setArgument(0, 'app');
44
        $this->registerService('monolog.logger.foo', \Monolog\Logger::class)->setArgument(0, 'foo');
45
46
        $this->compile();
47
48
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('monolog.logger', 'pushHandler', [new Reference('ekino.new_relic.logs_handler')]);
49
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('monolog.logger.foo', 'pushHandler', [new Reference('ekino.new_relic.logs_handler')]);
50
    }
51
52
    public function testProcessChannelExcludeChannels()
53
    {
54
        $this->container->setParameter('ekino.new_relic.monolog.channels', ['type' => 'exclusive', 'elements' => ['foo']]);
55
        $this->registerService('monolog.logger', \Monolog\Logger::class)->setArgument(0, 'app');
56
        $this->registerService('monolog.logger.foo', \Monolog\Logger::class)->setArgument(0, 'foo');
57
58
        $this->compile();
59
60
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('monolog.logger', 'pushHandler', [new Reference('ekino.new_relic.logs_handler')]);
61
    }
62
}
63