Passed
Pull Request — master (#149)
by Pierre
03:06
created

DictionaryBuildingPassSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 65
c 2
b 0
f 0
dl 0
loc 125
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_builds_a_key_value_dictionary_from_the_config() 0 38 1
A it_builds_a_value_dictionary_from_the_config() 0 38 1
A it_is_initializable() 0 3 1
A it_builds_a_value_as_key_dictionary_from_the_config() 0 38 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler;
6
7
use Assert\Assert;
8
use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryBuildingPass;
9
use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryRegistrationPass;
10
use Knp\DictionaryBundle\Dictionary;
11
use Knp\DictionaryBundle\Dictionary\Factory\Aggregate;
12
use PhpSpec\ObjectBehavior;
13
use Prophecy\Argument;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
16
final class DictionaryBuildingPassSpec extends ObjectBehavior
17
{
18
    function it_is_initializable()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
    {
20
        $this->shouldHaveType(DictionaryBuildingPass::class);
21
    }
22
23
    function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $container)
24
    {
25
        $config = [
26
            'dictionaries' => [
27
                'dico1' => [
28
                    'type'    => Dictionary::VALUE_AS_KEY,
29
                    'content' => ['foo', 'bar', 'baz'],
30
                ],
31
            ],
32
        ];
33
34
        $container->getParameter('knp_dictionary.configuration')->willReturn($config);
35
        $container->setDefinition(
36
            'knp_dictionary.dictionary.dico1',
37
            Argument::that(function ($definition): bool {
0 ignored issues
show
Bug introduced by
Prophecy\Argument::that(...ion(...) { /* ... */ }) of type Prophecy\Argument\Token\CallbackToken is incompatible with the type Symfony\Component\DependencyInjection\Definition expected by parameter $definition of Symfony\Component\Depend...uilder::setDefinition(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
            /** @scrutinizer ignore-type */ Argument::that(function ($definition): bool {
Loading history...
38
                Assert::that($definition->getClass())->eq(Dictionary::class);
39
40
                $factory = $definition->getFactory();
41
42
                Assert::that($factory[0]->__toString())->eq(Aggregate::class);
43
44
                Assert::that($factory[1])->eq('create');
45
46
                Assert::that($definition->getArguments())->eq([
47
                    'dico1',
48
                    [
49
                        'type'    => Dictionary::VALUE_AS_KEY,
50
                        'content' => ['foo', 'bar', 'baz'],
51
                    ],
52
                ]);
53
54
                Assert::that($definition->getTags())->eq([DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]);
55
56
                return true;
57
            })
58
        )->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled() does not exist on Symfony\Component\DependencyInjection\Definition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        )->/** @scrutinizer ignore-call */ shouldBeCalled();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
60
        $this->process($container);
0 ignored issues
show
Bug introduced by
The method process() does not exist on spec\Knp\DictionaryBundl...tionaryBuildingPassSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        $this->/** @scrutinizer ignore-call */ 
61
               process($container);
Loading history...
61
    }
62
63
    function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $container)
64
    {
65
        $config = [
66
            'dictionaries' => [
67
                'dico1' => [
68
                    'type'    => Dictionary::VALUE,
69
                    'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
70
                ],
71
            ],
72
        ];
73
74
        $container->getParameter('knp_dictionary.configuration')->willReturn($config);
75
        $container->setDefinition(
76
            'knp_dictionary.dictionary.dico1',
77
            Argument::that(function ($definition): bool {
0 ignored issues
show
Bug introduced by
Prophecy\Argument::that(...ion(...) { /* ... */ }) of type Prophecy\Argument\Token\CallbackToken is incompatible with the type Symfony\Component\DependencyInjection\Definition expected by parameter $definition of Symfony\Component\Depend...uilder::setDefinition(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
            /** @scrutinizer ignore-type */ Argument::that(function ($definition): bool {
Loading history...
78
                Assert::that($definition->getClass())->eq(Dictionary::class);
79
80
                $factory = $definition->getFactory();
81
82
                Assert::that($factory[0]->__toString())->eq(Aggregate::class);
83
84
                Assert::that($factory[1])->eq('create');
85
86
                Assert::that($definition->getArguments())->eq([
87
                    'dico1',
88
                    [
89
                        'type'    => Dictionary::VALUE,
90
                        'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
91
                    ],
92
                ]);
93
94
                Assert::that($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]);
95
96
                return true;
97
            })
98
        )->shouldBeCalled();
99
100
        $this->process($container);
101
    }
102
103
    function it_builds_a_key_value_dictionary_from_the_config(ContainerBuilder $container)
104
    {
105
        $config = [
106
            'dictionaries' => [
107
                'dico1' => [
108
                    'type'    => Dictionary::KEY_VALUE,
109
                    'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
110
                ],
111
            ],
112
        ];
113
114
        $container->getParameter('knp_dictionary.configuration')->willReturn($config);
115
        $container->setDefinition(
116
            'knp_dictionary.dictionary.dico1',
117
            Argument::that(function ($definition): bool {
0 ignored issues
show
Bug introduced by
Prophecy\Argument::that(...ion(...) { /* ... */ }) of type Prophecy\Argument\Token\CallbackToken is incompatible with the type Symfony\Component\DependencyInjection\Definition expected by parameter $definition of Symfony\Component\Depend...uilder::setDefinition(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
            /** @scrutinizer ignore-type */ Argument::that(function ($definition): bool {
Loading history...
118
                Assert::that($definition->getClass())->eq(Dictionary::class);
119
120
                $factory = $definition->getFactory();
121
122
                Assert::that($factory[0]->__toString())->eq(Aggregate::class);
123
124
                Assert::that($factory[1])->eq('create');
125
126
                Assert::that($definition->getArguments())->eq([
127
                    'dico1',
128
                    [
129
                        'type'    => Dictionary::KEY_VALUE,
130
                        'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
131
                    ],
132
                ]);
133
134
                Assert::that($definition->getTags())->eq([DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]);
135
136
                return true;
137
            })
138
        )->shouldBeCalled();
139
140
        $this->process($container);
141
    }
142
}
143