1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Knp\DictionaryBundle\Dictionary\Factory; |
6
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\Dictionary\Factory; |
8
|
|
|
use Knp\DictionaryBundle\Dictionary\Factory\KeyValue; |
9
|
|
|
use Knp\DictionaryBundle\ValueTransformer; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
|
12
|
|
|
final class KeyValueSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
function let(ValueTransformer $transformer) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$this->beConstructedWith($transformer); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function it_is_initializable() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$this->shouldHaveType(KeyValue::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function it_is_a_factory() |
25
|
|
|
{ |
26
|
|
|
$this->shouldHaveType(Factory::class); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_supports_specific_config() |
30
|
|
|
{ |
31
|
|
|
$this->supports(['type' => 'key_value'])->shouldReturn(true); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_throws_exception_if_no_content_is_provided() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
38
|
|
|
->during('create', ['yolo', []]) |
39
|
|
|
; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_creates_a_dictionary($transformer) |
43
|
|
|
{ |
44
|
|
|
$config = [ |
45
|
|
|
'content' => [ |
46
|
|
|
'foo1' => 'bar1', |
47
|
|
|
'foo2' => 'bar2', |
48
|
|
|
'foo3' => 'bar3', |
49
|
|
|
], |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
$transformer->transform('bar1')->willReturn('bar1'); |
53
|
|
|
$transformer->transform('bar2')->willReturn('bar2'); |
54
|
|
|
$transformer->transform('bar3')->willReturn('bar3'); |
55
|
|
|
$transformer->transform('foo1')->willReturn('foo1'); |
56
|
|
|
$transformer->transform('foo2')->willReturn('foo2'); |
57
|
|
|
$transformer->transform('foo3')->willReturn('foo3'); |
58
|
|
|
|
59
|
|
|
$dictionary = $this->create('yolo', $config); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$dictionary->getName()->shouldBe('yolo'); |
62
|
|
|
$dictionary->getValues()->shouldBe([ |
63
|
|
|
'foo1' => 'bar1', |
64
|
|
|
'foo2' => 'bar2', |
65
|
|
|
'foo3' => 'bar3', |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.