Completed
Push — master ( a5a753...454108 )
by Wachter
07:05
created

HandlerCompilerPassTest::testProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 22
rs 9.2
c 1
b 0
f 1
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
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 Task\TaskBundle\Unit\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Definition;
16
use Symfony\Component\DependencyInjection\Reference;
17
use Task\TaskBundle\DependencyInjection\HandlerCompilerPass;
18
19
/**
20
 * Tests for class HandlerCompilerPass.
21
 */
22
class HandlerCompilerPassTest extends \PHPUnit_Framework_TestCase
23
{
24
    public function testProcess()
25
    {
26
        $container = $this->prophesize(ContainerBuilder::class);
27
28
        $container->has(HandlerCompilerPass::REGISTRY_ID)->willReturn(true);
29
        $container->findTaggedServiceIds(HandlerCompilerPass::HANDLER_TAG)->willReturn(
30
            ['service1' => [], 'service2' => []]
31
        );
32
        $container->getDefinition('service1')->willReturn(new Definition(\stdClass::class));
33
        $container->getDefinition('service2')->willReturn(new Definition(self::class));
34
35
        $serviceDefinition = $this->prophesize(Definition::class);
36
        $container->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($serviceDefinition);
37
38
        $compilerPass = new HandlerCompilerPass();
39
        $compilerPass->process($container->reveal());
40
41
        $serviceDefinition->replaceArgument(
42
            0,
43
            [\stdClass::class => new Reference('service1'), self::class => new Reference('service2')]
44
        )->shouldBeCalled();
45
    }
46
47
    public function testProcessNoTaggedService()
48
    {
49
        $container = $this->prophesize(ContainerBuilder::class);
50
51
        $container->has(HandlerCompilerPass::REGISTRY_ID)->willReturn(true);
52
        $container->findTaggedServiceIds(HandlerCompilerPass::HANDLER_TAG)->willReturn([]);
53
54
        $serviceDefinition = $this->prophesize(Definition::class);
55
        $container->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($serviceDefinition);
56
57
        $compilerPass = new HandlerCompilerPass();
58
        $compilerPass->process($container->reveal());
59
60
        $serviceDefinition->replaceArgument(0, [])->shouldBeCalled();
61
    }
62
}
63