it_builds_a_value_dictionary_from_the_config()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 41
rs 9.568
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler;
6
7
use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryBuildingPass;
8
use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryRegistrationPass;
9
use Knp\DictionaryBundle\Dictionary;
10
use Knp\DictionaryBundle\Dictionary\Factory\Aggregate;
11
use PhpSpec\ObjectBehavior;
12
use Prophecy\Argument;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Webmozart\Assert\Assert;
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);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on UnitEnum. ( Ignorable by Annotation )

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

34
        $container->getParameter('knp_dictionary.configuration')->/** @scrutinizer ignore-call */ willReturn($config);

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...
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::eq($definition->getClass(), Dictionary::class);
39
40
                $factory = $definition->getFactory();
41
42
                Assert::eq((string) $factory[0], Aggregate::class);
43
44
                Assert::eq($factory[1], 'create');
45
46
                Assert::eq(
47
                    $definition->getArguments(),
48
                    [
49
                        'dico1',
50
                        [
51
                            'type'    => Dictionary::VALUE_AS_KEY,
52
                            'content' => ['foo', 'bar', 'baz'],
53
                        ],
54
                    ]
55
                );
56
57
                Assert::eq(
58
                    $definition->getTags(),
59
                    [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]
60
                );
61
62
                return true;
63
            })
64
        )->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

64
        )->/** @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...
65
66
        $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

66
        $this->/** @scrutinizer ignore-call */ 
67
               process($container);
Loading history...
67
    }
68
69
    function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $container)
70
    {
71
        $config = [
72
            'dictionaries' => [
73
                'dico1' => [
74
                    'type'    => Dictionary::VALUE,
75
                    'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
76
                ],
77
            ],
78
        ];
79
80
        $container->getParameter('knp_dictionary.configuration')->willReturn($config);
81
        $container->setDefinition(
82
            'knp_dictionary.dictionary.dico1',
83
            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

83
            /** @scrutinizer ignore-type */ Argument::that(function ($definition): bool {
Loading history...
84
                Assert::eq($definition->getClass(), Dictionary::class);
85
86
                $factory = $definition->getFactory();
87
88
                Assert::eq((string) $factory[0], Aggregate::class);
89
90
                Assert::eq($factory[1], 'create');
91
92
                Assert::eq(
93
                    $definition->getArguments(),
94
                    [
95
                        'dico1',
96
                        [
97
                            'type'    => Dictionary::VALUE,
98
                            'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
99
                        ],
100
                    ]
101
                );
102
103
                Assert::eq($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]);
104
105
                return true;
106
            })
107
        )->shouldBeCalled();
108
109
        $this->process($container);
110
    }
111
112
    function it_builds_a_key_value_dictionary_from_the_config(ContainerBuilder $container)
113
    {
114
        $config = [
115
            'dictionaries' => [
116
                'dico1' => [
117
                    'type'    => Dictionary::KEY_VALUE,
118
                    'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
119
                ],
120
            ],
121
        ];
122
123
        $container->getParameter('knp_dictionary.configuration')->willReturn($config);
124
        $container->setDefinition(
125
            'knp_dictionary.dictionary.dico1',
126
            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

126
            /** @scrutinizer ignore-type */ Argument::that(function ($definition): bool {
Loading history...
127
                Assert::eq($definition->getClass(), Dictionary::class);
128
129
                $factory = $definition->getFactory();
130
131
                Assert::eq((string) $factory[0], Aggregate::class);
132
133
                Assert::eq($factory[1], 'create');
134
135
                Assert::eq(
136
                    $definition->getArguments(),
137
                    [
138
                        'dico1',
139
                        [
140
                            'type'    => Dictionary::KEY_VALUE,
141
                            'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'],
142
                        ],
143
                    ]
144
                );
145
146
                Assert::eq($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]);
147
148
                return true;
149
            })
150
        )->shouldBeCalled();
151
152
        $this->process($container);
153
    }
154
}
155