IteratorSpec   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
c 1
b 0
f 0
dl 0
loc 107
rs 10
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A execution() 0 15 2
A it_is_hydrated_just_once() 0 12 1
A it_provides_a_set_of_values() 0 6 1
A it_supports_some_array_access_functions() 0 12 1
A its_getname_should_return_dictionary_name() 0 3 1
A let() 0 5 1
A it_generates_an_iterator() 0 6 1
A it_is_initializable() 0 3 1
A it_provides_a_set_of_keys() 0 6 1
A it_access_to_value_like_an_array() 0 5 1
A it_is_a_dictionary() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Knp\DictionaryBundle\Dictionary;
6
7
use Knp\DictionaryBundle\Dictionary;
8
use Knp\DictionaryBundle\Dictionary\Iterator;
9
use PhpSpec\ObjectBehavior;
10
11
final class IteratorSpec extends ObjectBehavior
12
{
13
    /**
14
     * @var bool
15
     */
16
    private $executed;
17
18
    function let()
19
    {
20
        $this->executed = false;
21
22
        $this->beConstructedWith('foo', $this->execution());
23
    }
24
25
    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...
26
    {
27
        $this->shouldHaveType(Iterator::class);
28
    }
29
30
    function it_is_a_dictionary()
31
    {
32
        $this->shouldImplement(Dictionary::class);
33
    }
34
35
    function it_supports_some_array_access_functions()
36
    {
37
        $dictionary = $this->getWrappedObject();
38
39
        $this['foo']->shouldBe(0);
40
        $this->shouldHaveKey('foo');
41
42
        $this['foo'] = 'test';
43
        $this['foo']->shouldBe('test');
44
45
        unset($dictionary['foo']);
46
        $this->shouldNotHaveKey('foo');
47
    }
48
49
    function it_provides_a_set_of_values()
50
    {
51
        $this->getValues()->shouldReturn([
0 ignored issues
show
Bug introduced by
The method getValues() does not exist on spec\Knp\DictionaryBundle\Dictionary\IteratorSpec. 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

51
        $this->/** @scrutinizer ignore-call */ 
52
               getValues()->shouldReturn([
Loading history...
52
            'foo' => 0,
53
            'bar' => 1,
54
            'baz' => 2,
55
        ]);
56
    }
57
58
    function it_provides_a_set_of_keys()
59
    {
60
        $this->getKeys()->shouldReturn([
0 ignored issues
show
Bug introduced by
The method getKeys() does not exist on spec\Knp\DictionaryBundle\Dictionary\IteratorSpec. 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
               getKeys()->shouldReturn([
Loading history...
61
            'foo',
62
            'bar',
63
            'baz',
64
        ]);
65
    }
66
67
    function it_is_hydrated_just_once()
68
    {
69
        $this->getValues()->shouldReturn([
70
            'foo' => 0,
71
            'bar' => 1,
72
            'baz' => 2,
73
        ]);
74
75
        $this->getValues()->shouldReturn([
76
            'foo' => 0,
77
            'bar' => 1,
78
            'baz' => 2,
79
        ]);
80
    }
81
82
    function it_access_to_value_like_an_array()
83
    {
84
        $this['foo']->shouldReturn(0);
85
        $this['bar']->shouldReturn(1);
86
        $this['baz']->shouldReturn(2);
87
    }
88
89
    function it_generates_an_iterator()
90
    {
91
        $this->shouldIterateLike([
92
            'foo' => 0,
93
            'bar' => 1,
94
            'baz' => 2,
95
        ]);
96
    }
97
98
    function its_getname_should_return_dictionary_name()
99
    {
100
        $this->getName()->shouldReturn('foo');
0 ignored issues
show
Bug introduced by
The method getName() does not exist on spec\Knp\DictionaryBundle\Dictionary\IteratorSpec. 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

100
        $this->/** @scrutinizer ignore-call */ 
101
               getName()->shouldReturn('foo');
Loading history...
101
    }
102
103
    private function execution(): iterable
104
    {
105
        if (!$this->executed) {
106
            $this->executed = true;
107
108
            yield 'foo' => 0;
109
110
            yield 'bar' => 1;
111
112
            yield 'baz' => 2;
113
114
            return;
115
        }
116
117
        throw new \Exception('Executed twice.');
118
    }
119
}
120