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\Value; |
9
|
|
|
use Knp\DictionaryBundle\ValueTransformer; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
|
12
|
|
|
final class ValueSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
function let(ValueTransformer $transformer) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$this->beConstructedWith($transformer); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function it_is_initializable() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$this->shouldHaveType(Value::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' => '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' => ['bar1', 'bar2', 'bar3'], |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
$transformer->transform('bar1')->willReturn('bar1'); |
49
|
|
|
$transformer->transform('bar2')->willReturn('bar2'); |
50
|
|
|
$transformer->transform('bar3')->willReturn('bar3'); |
51
|
|
|
|
52
|
|
|
$dictionary = $this->create('yolo', $config); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$dictionary->getName()->shouldBe('yolo'); |
55
|
|
|
$dictionary->getValues()->shouldBe(['bar1', 'bar2', 'bar3']); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.