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

IteratorSpec::it_is_initializable()   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 Exception;
8
use Knp\DictionaryBundle\Dictionary;
9
use Knp\DictionaryBundle\Dictionary\Iterator;
10
use PhpSpec\ObjectBehavior;
11
12
final class IteratorSpec extends ObjectBehavior
13
{
14
    /**
15
     * @var bool
16
     */
17
    private $executed;
18
19
    function let()
20
    {
21
        $this->executed = false;
22
23
        $this->beConstructedWith('foo', $this->execution());
24
    }
25
26
    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...
27
    {
28
        $this->shouldHaveType(Iterator::class);
29
    }
30
31
    function it_is_a_dictionary()
32
    {
33
        $this->shouldImplement(Dictionary::class);
34
    }
35
36
    function it_supports_some_array_access_functions()
37
    {
38
        $dictionary = $this->getWrappedObject();
39
40
        $this['foo']->shouldBe(0);
41
        $this->offsetExists('foo')->shouldReturn(true);
42
43
        $this['foo'] = 'test';
44
        $this['foo']->shouldBe('test');
45
46
        unset($dictionary['foo']);
47
        $this->offsetExists('foo')->shouldReturn(false);
48
    }
49
50
    function it_provides_a_set_of_values()
51
    {
52
        $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

52
        $this->/** @scrutinizer ignore-call */ 
53
               getValues()->shouldReturn([
Loading history...
53
            'foo' => 0,
54
            'bar' => 1,
55
            'baz' => 2,
56
        ]);
57
    }
58
59
    function it_provides_a_set_of_keys()
60
    {
61
        $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

61
        $this->/** @scrutinizer ignore-call */ 
62
               getKeys()->shouldReturn([
Loading history...
62
            'foo',
63
            'bar',
64
            'baz',
65
        ]);
66
    }
67
68
    function it_is_hydrated_just_once()
69
    {
70
        $this->getValues()->shouldReturn([
71
            'foo' => 0,
72
            'bar' => 1,
73
            'baz' => 2,
74
        ]);
75
76
        $this->getValues()->shouldReturn([
77
            'foo' => 0,
78
            'bar' => 1,
79
            'baz' => 2,
80
        ]);
81
    }
82
83
    function it_access_to_value_like_an_array()
84
    {
85
        $this['foo']->shouldReturn(0);
86
        $this['bar']->shouldReturn(1);
87
        $this['baz']->shouldReturn(2);
88
    }
89
90
    function it_generates_an_iterator()
91
    {
92
        $this->shouldIterateLike([
93
            'foo' => 0,
94
            'bar' => 1,
95
            'baz' => 2,
96
        ]);
97
    }
98
99
    function its_getname_should_return_dictionary_name()
100
    {
101
        $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

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