Passed
Push — master ( 414f0a...c0888e )
by Pierre
03:03
created

TraceableSpec::it_is_a_dictionary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Knp\DictionaryBundle\Dictionary;
6
7
use Assert\Assert;
8
use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector;
9
use Knp\DictionaryBundle\Dictionary;
10
use Knp\DictionaryBundle\Dictionary\Simple;
11
use Knp\DictionaryBundle\Dictionary\Traceable;
12
use PhpSpec\ObjectBehavior;
13
14
final class TraceableSpec extends ObjectBehavior
15
{
16
    /**
17
     * @var DictionaryDataCollector
18
     */
19
    private $collector;
20
21
    function let()
22
    {
23
        $dictionary = new Simple('name', [
24
            'foo' => 'bar',
25
            'baz' => null,
26
        ]);
27
28
        $this->collector = new DictionaryDataCollector();
29
30
        $this->beConstructedWith($dictionary, $this->collector);
31
    }
32
33
    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...
34
    {
35
        $this->shouldHaveType(Traceable::class);
36
    }
37
38
    function it_is_a_dictionary()
39
    {
40
        $this->shouldImplement(Dictionary::class);
41
    }
42
43
    function it_has_a_name()
44
    {
45
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
46
47
        $this->getName()->shouldReturn('name');
0 ignored issues
show
Bug introduced by
The method getName() does not exist on spec\Knp\DictionaryBundle\Dictionary\TraceableSpec. 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

47
        $this->/** @scrutinizer ignore-call */ 
48
               getName()->shouldReturn('name');
Loading history...
48
49
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
50
    }
51
52
    function it_traces_keys()
53
    {
54
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
55
56
        $this->getKeys()->shouldReturn(['foo', 'baz']);
0 ignored issues
show
Bug introduced by
The method getKeys() does not exist on spec\Knp\DictionaryBundle\Dictionary\TraceableSpec. 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

56
        $this->/** @scrutinizer ignore-call */ 
57
               getKeys()->shouldReturn(['foo', 'baz']);
Loading history...
57
58
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
59
            ->eq([
60
                'name' => [
61
                    [
62
                        'key'   => 'foo',
63
                        'value' => 'bar',
64
                    ],
65
                    [
66
                        'key'   => 'baz',
67
                        'value' => null,
68
                    ],
69
                ],
70
            ])
71
        ;
72
    }
73
74
    function it_traces_values()
75
    {
76
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
77
78
        $this->getValues()->shouldReturn(['foo' => 'bar', 'baz' => null]);
0 ignored issues
show
Bug introduced by
The method getValues() does not exist on spec\Knp\DictionaryBundle\Dictionary\TraceableSpec. 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

78
        $this->/** @scrutinizer ignore-call */ 
79
               getValues()->shouldReturn(['foo' => 'bar', 'baz' => null]);
Loading history...
79
80
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
81
            ->eq([
82
                'name' => [
83
                    [
84
                        'key'   => 'foo',
85
                        'value' => 'bar',
86
                    ],
87
                    [
88
                        'key'   => 'baz',
89
                        'value' => null,
90
                    ],
91
                ],
92
            ])
93
        ;
94
    }
95
96
    function it_traces_values_get()
97
    {
98
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
99
100
        $this['foo']->shouldReturn('bar');
101
102
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
103
            ->eq([
104
                'name' => [
105
                    [
106
                        'key'   => 'foo',
107
                        'value' => 'bar',
108
                    ],
109
                    [
110
                        'key'   => 'baz',
111
                        'value' => null,
112
                    ],
113
                ],
114
            ])
115
        ;
116
    }
117
118
    function it_traces_value_set()
119
    {
120
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
121
122
        $this['yo'] = 'lo';
123
124
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
125
            ->eq([
126
                'name' => [
127
                    [
128
                        'key'   => 'foo',
129
                        'value' => 'bar',
130
                    ],
131
                    [
132
                        'key'   => 'baz',
133
                        'value' => null,
134
                    ],
135
                    [
136
                        'key'   => 'yo',
137
                        'value' => 'lo',
138
                    ],
139
                ],
140
            ])
141
        ;
142
    }
143
144
    function it_traces_value_unset()
145
    {
146
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
147
148
        unset($this['foo']);
149
150
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
151
            ->eq([
152
                'name' => [
153
                    [
154
                        'key'   => 'baz',
155
                        'value' => null,
156
                    ],
157
                ],
158
            ])
159
        ;
160
    }
161
162
    function it_traces_key_exists()
163
    {
164
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
165
166
        $this->offsetExists('baz')->shouldReturn(true);
167
168
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
169
            ->eq([
170
                'name' => [
171
                    [
172
                        'key'   => 'foo',
173
                        'value' => 'bar',
174
                    ],
175
                    [
176
                        'key'   => 'baz',
177
                        'value' => null,
178
                    ],
179
                ],
180
            ])
181
        ;
182
    }
183
184
    function it_trace_iteration()
185
    {
186
        Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent();
187
188
        $this->shouldIterateLike([
189
            'foo' => 'bar',
190
            'baz' => null,
191
        ]);
192
193
        Assert::that(iterator_to_array($this->collector->getDictionaries()))
194
            ->eq([
195
                'name' => [
196
                    [
197
                        'key'   => 'foo',
198
                        'value' => 'bar',
199
                    ],
200
                    [
201
                        'key'   => 'baz',
202
                        'value' => null,
203
                    ],
204
                ],
205
            ])
206
        ;
207
    }
208
209
    function it_delegates_the_count_to_the_other_dictionary()
210
    {
211
        $this->count()->shouldReturn(2);
0 ignored issues
show
Bug introduced by
The method count() does not exist on spec\Knp\DictionaryBundle\Dictionary\TraceableSpec. 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

211
        $this->/** @scrutinizer ignore-call */ 
212
               count()->shouldReturn(2);
Loading history...
212
    }
213
}
214