Completed
Pull Request — master (#2)
by Wachter
03:01
created

TaskCompilerPassTest::testProcess()   C

Complexity

Conditions 10
Paths 1

Size

Total Lines 84
Code Lines 56

Duplication

Lines 14
Ratio 16.67 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 14
loc 84
rs 5.3846
cc 10
eloc 56
nc 1
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
use Task\TaskBundle\DependencyInjection\TaskCompilerPass;
10
11
class TaskCompilerPassTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testProcess()
14
    {
15
        $containerBuilder = $this->prophesize(ContainerBuilder::class);
16
        $schedulerDefinition = $this->prophesize(Definition::class);
17
        $handler1Definition = $this->prophesize(Definition::class);
18
        $handler2Definition = $this->prophesize(Definition::class);
19
20
        $containerBuilder->has(TaskCompilerPass::SCHEDULER_ID)->willReturn(true);
21
        $containerBuilder->getDefinition(TaskCompilerPass::SCHEDULER_ID)->willReturn($schedulerDefinition->reveal());
22
        $containerBuilder->getDefinition('id-1')->willReturn($handler1Definition->reveal());
23
        $containerBuilder->getDefinition('id-2')->willReturn($handler2Definition->reveal());
24
25
        $containerBuilder->findTaggedServiceIds(TaskCompilerPass::INTERVAL_TAG)
26
            ->willReturn(
27
                [
28
                    'id-1' => [
29
                        [
30
                            TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily',
31
                            TaskCompilerPass::WORKLOAD_ATTRIBUTE => 'test-workload',
32
                            TaskCompilerPass::KEY_ATTRIBUTE => 'test-key'
33
                        ],
34
                    ],
35
                    'id-2' => [
36
                        [
37
                            TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily',
38
                            TaskCompilerPass::KEY_ATTRIBUTE => 'test-key-1'
39
                        ],
40
                        [
41
                            TaskCompilerPass::INTERVAL_ATTRIBUTE => 'daily',
42
                            TaskCompilerPass::WORKLOAD_ATTRIBUTE => 'test-workload-2'
43
                        ],
44
                    ],
45
                ]
46
            );
47
48
        $handler1Definition->getTag(HandlerCompilerPass::HANDLER_TAG)->willReturn(
49
            [[HandlerCompilerPass::HANDLER_NAME_ATTRIBUTE => 'handler-1']]
50
        );
51
        $handler2Definition->getTag(HandlerCompilerPass::HANDLER_TAG)->willReturn(
52
            [[HandlerCompilerPass::HANDLER_NAME_ATTRIBUTE => 'handler-2']]
53
        );
54
55
        $compilerPass = new TaskCompilerPass();
56
        $compilerPass->process($containerBuilder->reveal());
57
58
        $schedulerDefinition->addMethodCall(
59
            TaskCompilerPass::CREATE_FUNCTION_NAME,
60
            Argument::that(
61
                function ($arguments) {
62
                    return
63
                        $arguments[0] === 'handler-1'
64
                        && $arguments[1] === 'test-workload'
65
                        && $arguments[2] === 'daily'
66
                        && $arguments[3] === 'test-key';
67
                }
68
            )
69
        )->shouldBeCalledTimes(1);
70
        $schedulerDefinition->addMethodCall(
71
            TaskCompilerPass::CREATE_FUNCTION_NAME,
72
            Argument::that(
73 View Code Duplication
                function ($arguments) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
                    return
75
                        $arguments[0] === 'handler-2'
76
                        && $arguments[1] === null
77
                        && $arguments[2] === 'daily'
78
                        && $arguments[3] === 'test-key';
79
                }
80
            )
81
        )->shouldBeCalledTimes(1);
82
        $schedulerDefinition->addMethodCall(
83
            TaskCompilerPass::CREATE_FUNCTION_NAME,
84
            Argument::that(
85 View Code Duplication
                function ($arguments) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
                    return
87
                        $arguments[0] === 'handler-2'
88
                        && $arguments[1] === 'test-workload-2'
89
                        && $arguments[2] === 'daily'
90
                        && $arguments[3] === 'handler-2_daily_s:15:"test-workload-2";';
91
                }
92
            )
93
        )->shouldBeCalledTimes(1);
94
95
        // TODO this test always returns true should be extended
96
    }
97
}
98