Completed
Push — master ( c2e487...7ac6a5 )
by Wachter
07:39
created

HandlerCompilerPassTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 52
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testProcess() 0 49 4
1
<?php
2
3
namespace Unit\DependencyInjection;
4
5
use Prophecy\Argument;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Task\TaskBundle\DependencyInjection\HandlerCompilerPass;
9
10
class HandlerCompilerPassTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testProcess()
13
    {
14
        $containerBuilder = $this->prophesize(ContainerBuilder::class);
15
        $definition = $this->prophesize(Definition::class);
16
17
        $containerBuilder->has(HandlerCompilerPass::REGISTRY_ID)->willReturn(true);
18
        $containerBuilder->findDefinition(HandlerCompilerPass::REGISTRY_ID)->willReturn($definition->reveal());
19
20
        $containerBuilder->findTaggedServiceIds(HandlerCompilerPass::HANDLER_TAG)
21
            ->willReturn(
22
                [
23
                    'id-1' => [
24
                        ['name' => 'name-1'],
25
                    ],
26
                    'id-2' => [
27
                        ['name' => 'name-2-1'],
28
                        ['name' => 'name-2-2'],
29
                    ],
30
                ]
31
            );
32
33
        $compilerPass = new HandlerCompilerPass();
34
        $compilerPass->process($containerBuilder->reveal());
35
36
        $definition->addMethodCall(
37
            HandlerCompilerPass::ADD_FUNCTION_NAME,
38
            Argument::that(
39
                function ($arguments) {
40
                    return $arguments[0] === 'name-1' && $arguments[1]->__toString() === 'id-1';
41
                }
42
            )
43
        )->shouldBeCalledTimes(1);
44
        $definition->addMethodCall(
45
            HandlerCompilerPass::ADD_FUNCTION_NAME,
46
            Argument::that(
47
                function ($arguments) {
48
                    return $arguments[0] === 'name-2-1' && $arguments[1]->__toString() === 'id-2';
49
                }
50
            )
51
        )->shouldBeCalledTimes(1);
52
        $definition->addMethodCall(
53
            HandlerCompilerPass::ADD_FUNCTION_NAME,
54
            Argument::that(
55
                function ($arguments) {
56
                    return $arguments[0] === 'name-2-2' && $arguments[1]->__toString() === 'id-2';
57
                }
58
            )
59
        )->shouldBeCalledTimes(1);
60
    }
61
}
62