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

HandlerCompilerPassTest::testProcess()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 49
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 49
rs 8.7972
cc 4
eloc 32
nc 1
nop 0
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