1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Knp\DictionaryBundle\Dictionary\Factory; |
6
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\Dictionary; |
8
|
|
|
use Knp\DictionaryBundle\Dictionary\Collection; |
9
|
|
|
use Knp\DictionaryBundle\Dictionary\Factory; |
10
|
|
|
use Knp\DictionaryBundle\Dictionary\Factory\Combined; |
11
|
|
|
use PhpSpec\ObjectBehavior; |
12
|
|
|
|
13
|
|
|
final class CombinedSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
function let() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->beConstructedWith(new Collection()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function it_is_initializable() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$this->shouldHaveType(Combined::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function it_is_a_factory() |
26
|
|
|
{ |
27
|
|
|
$this->shouldHaveType(Factory::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_supports_specific_config() |
31
|
|
|
{ |
32
|
|
|
$this->supports(['type' => 'combined'])->shouldReturn(true); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_creates_a_dictionary(Dictionary $dictionary1, Dictionary $dictionary2, Dictionary $dictionary3) |
36
|
|
|
{ |
37
|
|
|
$dictionary1->getIterator()->willReturn(new \ArrayIterator(['foo1' => 'foo10', 'foo2' => 'foo20'])); |
|
|
|
|
38
|
|
|
$dictionary1->getName()->willReturn('dictionary1'); |
39
|
|
|
|
40
|
|
|
$dictionary2->getIterator()->willReturn(new \ArrayIterator(['bar1' => 'bar10', 'bar2' => 'bar20'])); |
41
|
|
|
$dictionary2->getName()->willReturn('dictionary2'); |
42
|
|
|
|
43
|
|
|
$dictionary3->getIterator()->willReturn(new \ArrayIterator(['foo2' => 'baz20', 'bar2' => 'baz20'])); |
44
|
|
|
$dictionary3->getName()->willReturn('dictionary3'); |
45
|
|
|
|
46
|
|
|
$this->beConstructedWith(new Collection($dictionary1->getWrappedObject(), $dictionary2->getWrappedObject(), $dictionary3->getWrappedObject())); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$config = [ |
49
|
|
|
'type' => 'combined', |
50
|
|
|
'dictionaries' => [ |
51
|
|
|
'dictionary1', |
52
|
|
|
'dictionary2', |
53
|
|
|
'dictionary3', |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
$dictionary = $this->create('combined_dictionary', $config); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$dictionary->getValues()->shouldReturn([ |
60
|
|
|
'foo1' => 'foo10', |
61
|
|
|
'foo2' => 'baz20', |
62
|
|
|
'bar1' => 'bar10', |
63
|
|
|
'bar2' => 'baz20', |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.