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\Combined; |
9
|
|
|
use PhpSpec\ObjectBehavior; |
10
|
|
|
|
11
|
|
|
final class CombinedSpec extends ObjectBehavior |
12
|
|
|
{ |
13
|
|
|
function let(Dictionary $dictionary1, Dictionary $dictionary2, Dictionary $dictionary3) |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$this->beConstructedWith( |
16
|
|
|
'combined_dictionary', |
17
|
|
|
$dictionary1, |
18
|
|
|
$dictionary2, |
19
|
|
|
$dictionary3 |
20
|
|
|
); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_is_initializable() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$this->shouldHaveType(Combined::class); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_a_dictionary() |
29
|
|
|
{ |
30
|
|
|
$this->shouldImplement(Dictionary::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_access_to_value_like_an_array($dictionary1, $dictionary2, $dictionary3) |
34
|
|
|
{ |
35
|
|
|
$dictionary1->getIterator()->willReturn(new \ArrayIterator(['foo1' => 'foo10'])); |
36
|
|
|
|
37
|
|
|
$dictionary2->getIterator()->willReturn(new \ArrayIterator(['bar1' => 'bar10'])); |
38
|
|
|
|
39
|
|
|
$dictionary3->getIterator()->willReturn(new \ArrayIterator(['baz1' => 'baz10'])); |
40
|
|
|
|
41
|
|
|
$this['foo1']->shouldBe('foo10'); |
42
|
|
|
$this['bar1']->shouldBe('bar10'); |
43
|
|
|
$this['baz1']->shouldBe('baz10'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_getvalues_should_return_dictionaries_values($dictionary1, $dictionary2, $dictionary3) |
47
|
|
|
{ |
48
|
|
|
$dictionary1->getIterator()->willReturn(new \ArrayIterator([ |
49
|
|
|
'foo1' => 'foo10', |
50
|
|
|
'foo2' => 'foo20', |
51
|
|
|
])); |
52
|
|
|
|
53
|
|
|
$dictionary2->getIterator()->willReturn(new \ArrayIterator([ |
54
|
|
|
'bar1' => 'bar10', |
55
|
|
|
'bar2' => 'bar20', |
56
|
|
|
])); |
57
|
|
|
|
58
|
|
|
$dictionary3->getIterator()->willReturn(new \ArrayIterator([ |
59
|
|
|
'foo1' => 'baz10', |
60
|
|
|
'bar2' => 'baz20', |
61
|
|
|
])); |
62
|
|
|
|
63
|
|
|
$this->getKeys()->shouldReturn([ |
|
|
|
|
64
|
|
|
'foo1', |
65
|
|
|
'foo2', |
66
|
|
|
'bar1', |
67
|
|
|
'bar2', |
68
|
|
|
]); |
69
|
|
|
$this->getValues()->shouldReturn([ |
|
|
|
|
70
|
|
|
'foo1' => 'baz10', |
71
|
|
|
'foo2' => 'foo20', |
72
|
|
|
'bar1' => 'bar10', |
73
|
|
|
'bar2' => 'baz20', |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function it_can_iterate_over_dictionaries($dictionary1, $dictionary2, $dictionary3) |
78
|
|
|
{ |
79
|
|
|
$dictionary1->getIterator()->willReturn(new \ArrayIterator([ |
80
|
|
|
'foo1' => 'foo10', |
81
|
|
|
'foo2' => 'foo20', |
82
|
|
|
])); |
83
|
|
|
|
84
|
|
|
$dictionary2->getIterator()->willReturn(new \ArrayIterator([ |
85
|
|
|
'bar1' => 'bar10', |
86
|
|
|
'bar2' => 'bar20', |
87
|
|
|
])); |
88
|
|
|
|
89
|
|
|
$dictionary3->getIterator()->willReturn(new \ArrayIterator([ |
90
|
|
|
'foo2' => 'baz20', |
91
|
|
|
'bar2' => 'baz20', |
92
|
|
|
])); |
93
|
|
|
|
94
|
|
|
$this->shouldIterateLike([ |
95
|
|
|
'foo1' => 'foo10', |
96
|
|
|
'foo2' => 'baz20', |
97
|
|
|
'bar1' => 'bar10', |
98
|
|
|
'bar2' => 'baz20', |
99
|
|
|
]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
function it_sums_the_count_of_elements($dictionary1, $dictionary2, $dictionary3) |
103
|
|
|
{ |
104
|
|
|
$dictionary1->getIterator()->willReturn(new \ArrayIterator([ |
105
|
|
|
'foo1' => 'foo10', |
106
|
|
|
])); |
107
|
|
|
|
108
|
|
|
$dictionary2->getIterator()->willReturn(new \ArrayIterator([ |
109
|
|
|
'bar1' => 'bar10', |
110
|
|
|
'bar2' => 'bar20', |
111
|
|
|
])); |
112
|
|
|
|
113
|
|
|
$dictionary3->getIterator()->willReturn(new \ArrayIterator([ |
114
|
|
|
'baz1' => 'baz10', |
115
|
|
|
'baz2' => 'baz20', |
116
|
|
|
'baz3' => 'baz30', |
117
|
|
|
'baz4' => 'baz40', |
118
|
|
|
])); |
119
|
|
|
|
120
|
|
|
$this->count()->shouldReturn(7); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
function its_getname_should_return_dictionary_name() |
124
|
|
|
{ |
125
|
|
|
$this->getName()->shouldReturn('combined_dictionary'); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.