44
55namespace spec \Knp \DictionaryBundle \Dictionary ;
66
7- use ArrayIterator ;
87use Knp \DictionaryBundle \Dictionary ;
98use Knp \DictionaryBundle \Dictionary \Combined ;
109use PhpSpec \ObjectBehavior ;
1110
1211final class CombinedSpec extends ObjectBehavior
1312{
14- function let (Dictionary $ dictionary1 , Dictionary $ dictionary2 , Dictionary $ dictionary3 )
13+ use DictionaryBehavior;
14+
15+ function let ()
1516 {
1617 $ this ->beConstructedWith (
1718 'combined_dictionary ' ,
18- $ dictionary1 ,
19- $ dictionary2 ,
20- $ dictionary3
19+ new Dictionary \Simple (
20+ 'dictionary1 ' ,
21+ [
22+ 'foo ' => 1 ,
23+ 'bar ' => 2 ,
24+ ]
25+ ),
26+ new Dictionary \Simple (
27+ 'dictionary2 ' ,
28+ [
29+ 'bar ' => 3 ,
30+ 'baz ' => 4 ,
31+ ]
32+ ),
33+ new Dictionary \Simple (
34+ 'dictionary3 ' ,
35+ [
36+ 'baz ' => 5 ,
37+ ]
38+ ),
2139 );
2240 }
2341
@@ -26,103 +44,17 @@ function it_is_initializable()
2644 $ this ->shouldHaveType (Combined::class);
2745 }
2846
29- function it_is_a_dictionary ()
30- {
31- $ this ->shouldImplement (Dictionary::class);
32- }
33-
34- function it_access_to_value_like_an_array ($ dictionary1 , $ dictionary2 , $ dictionary3 )
47+ protected function getExpectedResult (): array
3548 {
36- $ dictionary1 ->getIterator ()->willReturn (new ArrayIterator (['foo1 ' => 'foo10 ' ]));
37-
38- $ dictionary2 ->getIterator ()->willReturn (new ArrayIterator (['bar1 ' => 'bar10 ' ]));
39-
40- $ dictionary3 ->getIterator ()->willReturn (new ArrayIterator (['baz1 ' => 'baz10 ' ]));
41-
42- $ this ['foo1 ' ]->shouldBe ('foo10 ' );
43- $ this ['bar1 ' ]->shouldBe ('bar10 ' );
44- $ this ['baz1 ' ]->shouldBe ('baz10 ' );
45- }
46-
47- function it_getvalues_should_return_dictionaries_values ($ dictionary1 , $ dictionary2 , $ dictionary3 )
48- {
49- $ dictionary1 ->getIterator ()->willReturn (new ArrayIterator ([
50- 'foo1 ' => 'foo10 ' ,
51- 'foo2 ' => 'foo20 ' ,
52- ]));
53-
54- $ dictionary2 ->getIterator ()->willReturn (new ArrayIterator ([
55- 'bar1 ' => 'bar10 ' ,
56- 'bar2 ' => 'bar20 ' ,
57- ]));
58-
59- $ dictionary3 ->getIterator ()->willReturn (new ArrayIterator ([
60- 'foo1 ' => 'baz10 ' ,
61- 'bar2 ' => 'baz20 ' ,
62- ]));
63-
64- $ this ->getKeys ()->shouldReturn ([
65- 'foo1 ' ,
66- 'foo2 ' ,
67- 'bar1 ' ,
68- 'bar2 ' ,
69- ]);
70- $ this ->getValues ()->shouldReturn ([
71- 'foo1 ' => 'baz10 ' ,
72- 'foo2 ' => 'foo20 ' ,
73- 'bar1 ' => 'bar10 ' ,
74- 'bar2 ' => 'baz20 ' ,
75- ]);
76- }
77-
78- function it_can_iterate_over_dictionaries ($ dictionary1 , $ dictionary2 , $ dictionary3 )
79- {
80- $ dictionary1 ->getIterator ()->willReturn (new ArrayIterator ([
81- 'foo1 ' => 'foo10 ' ,
82- 'foo2 ' => 'foo20 ' ,
83- ]));
84-
85- $ dictionary2 ->getIterator ()->willReturn (new ArrayIterator ([
86- 'bar1 ' => 'bar10 ' ,
87- 'bar2 ' => 'bar20 ' ,
88- ]));
89-
90- $ dictionary3 ->getIterator ()->willReturn (new ArrayIterator ([
91- 'foo2 ' => 'baz20 ' ,
92- 'bar2 ' => 'baz20 ' ,
93- ]));
94-
95- $ this ->shouldIterateLike ([
96- 'foo1 ' => 'foo10 ' ,
97- 'foo2 ' => 'baz20 ' ,
98- 'bar1 ' => 'bar10 ' ,
99- 'bar2 ' => 'baz20 ' ,
100- ]);
101- }
102-
103- function it_sums_the_count_of_elements ($ dictionary1 , $ dictionary2 , $ dictionary3 )
104- {
105- $ dictionary1 ->getIterator ()->willReturn (new ArrayIterator ([
106- 'foo1 ' => 'foo10 ' ,
107- ]));
108-
109- $ dictionary2 ->getIterator ()->willReturn (new ArrayIterator ([
110- 'bar1 ' => 'bar10 ' ,
111- 'bar2 ' => 'bar20 ' ,
112- ]));
113-
114- $ dictionary3 ->getIterator ()->willReturn (new ArrayIterator ([
115- 'baz1 ' => 'baz10 ' ,
116- 'baz2 ' => 'baz20 ' ,
117- 'baz3 ' => 'baz30 ' ,
118- 'baz4 ' => 'baz40 ' ,
119- ]));
120-
121- $ this ->count ()->shouldReturn (7 );
49+ return [
50+ 'foo ' => 1 ,
51+ 'bar ' => 3 ,
52+ 'baz ' => 5 ,
53+ ];
12254 }
12355
124- function its_getname_should_return_dictionary_name ()
56+ protected function getExpectedName (): string
12557 {
126- $ this -> getName ()-> shouldReturn ( 'combined_dictionary ' ) ;
58+ return 'combined_dictionary ' ;
12759 }
12860}
0 commit comments