|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace spec\Knp\DictionaryBundle\Templating\Extension; |
|
6
|
|
|
|
|
7
|
|
|
use Knp\DictionaryBundle\Dictionary; |
|
8
|
|
|
use Knp\DictionaryBundle\Dictionary\Collection; |
|
9
|
|
|
use Knp\DictionaryBundle\Templating\Extension; |
|
10
|
|
|
use PhpSpec\ObjectBehavior; |
|
11
|
|
|
use Webmozart\Assert\Assert; |
|
12
|
|
|
|
|
13
|
|
|
final class DictionarySpec extends ObjectBehavior |
|
14
|
|
|
{ |
|
15
|
|
|
function let(Dictionary $dico1, Dictionary $dico2) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
$dico1->offsetGet('foo')->willReturn('bar'); |
|
18
|
|
|
$dico1->getName()->willReturn('test'); |
|
19
|
|
|
|
|
20
|
|
|
$dico2->offsetGet('foo')->willReturn(false); |
|
21
|
|
|
$dico2->getName()->willReturn('other'); |
|
22
|
|
|
|
|
23
|
|
|
$this->beConstructedWith(new Collection($dico1->getWrappedObject(), $dico2->getWrappedObject())); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
function it_is_initializable() |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
$this->shouldHaveType(Extension\Dictionary::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function it_has_a_filter_and_a_function() |
|
32
|
|
|
{ |
|
33
|
|
|
$filters = $this->getFilters(); |
|
|
|
|
|
|
34
|
|
|
$functions = $this->getFunctions(); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$filters[0]->getName()->shouldReturn('dictionary'); |
|
37
|
|
|
$functions[0]->getName()->shouldReturn('dictionary'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function it_returns_a_dictionary_by_its_name($dico1, $dico2) |
|
41
|
|
|
{ |
|
42
|
|
|
$functions = $this->getFunctions(); |
|
43
|
|
|
$callable = current($functions->getWrappedObject())->getCallable(); |
|
44
|
|
|
|
|
45
|
|
|
Assert::eq($callable('test'), $dico1->getWrappedObject()); |
|
46
|
|
|
Assert::eq($callable('other'), $dico2->getWrappedObject()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_returns_a_value_from_a_dictionary() |
|
50
|
|
|
{ |
|
51
|
|
|
$filters = $this->getFilters(); |
|
52
|
|
|
$callable = current($filters->getWrappedObject())->getCallable(); |
|
53
|
|
|
|
|
54
|
|
|
Assert::eq($callable('foo', 'test'), 'bar'); |
|
55
|
|
|
Assert::eq($callable('foo', 'other'), false); |
|
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.