1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Knp\DictionaryBundle\Form\Type; |
6
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\Dictionary; |
8
|
|
|
use Knp\DictionaryBundle\Dictionary\Collection; |
9
|
|
|
use Knp\DictionaryBundle\Form\Type\DictionaryType; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
use Prophecy\Argument; |
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
13
|
|
|
use Symfony\Component\OptionsResolver\Options; |
14
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
15
|
|
|
|
16
|
|
|
final class DictionaryTypeSpec extends ObjectBehavior |
17
|
|
|
{ |
18
|
|
|
function let() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$this->beConstructedWith(new Collection()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_is_initializable() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$this->shouldHaveType(DictionaryType::class); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_a_choice_form_type() |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
|
|
->getParent() |
|
|
|
|
32
|
|
|
->shouldReturn(ChoiceType::class) |
33
|
|
|
; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_has_default_options( |
37
|
|
|
OptionsResolver $resolver, |
38
|
|
|
Options $options, |
39
|
|
|
Dictionary $dictionary1, |
40
|
|
|
Dictionary $dictionary2 |
41
|
|
|
) { |
42
|
|
|
$dictionary1->getName()->willReturn('d1'); |
43
|
|
|
$dictionary2->getName()->willReturn('d2'); |
44
|
|
|
|
45
|
|
|
$dictionary1->getValues()->willReturn(['foo' => 'bar']); |
46
|
|
|
|
47
|
|
|
$dictionaries = new Collection($dictionary1->getWrappedObject(), $dictionary2->getWrappedObject()); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->beConstructedWith($dictionaries); |
50
|
|
|
|
51
|
|
|
$resolver |
52
|
|
|
->setDefault('choices', Argument::that(function ($callable) use ($options): bool { |
53
|
|
|
$options->offsetGet('name')->willReturn('d1'); |
54
|
|
|
|
55
|
|
|
return $callable($options->getWrappedObject()) === array_flip(['foo' => 'bar']); |
|
|
|
|
56
|
|
|
})) |
57
|
|
|
->willReturn($resolver) |
|
|
|
|
58
|
|
|
->shouldBeCalled() |
59
|
|
|
; |
60
|
|
|
|
61
|
|
|
$resolver |
62
|
|
|
->setRequired(['name']) |
63
|
|
|
->willReturn($resolver) |
64
|
|
|
->shouldBeCalled() |
65
|
|
|
; |
66
|
|
|
|
67
|
|
|
$resolver |
68
|
|
|
->setAllowedValues('name', ['d1', 'd2']) |
69
|
|
|
->willReturn($resolver) |
70
|
|
|
->shouldBeCalled() |
71
|
|
|
; |
72
|
|
|
|
73
|
|
|
$this->configureOptions($resolver); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.