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\Extended; |
11
|
|
|
use PhpSpec\ObjectBehavior; |
12
|
|
|
|
13
|
|
|
final class ExtendedSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
function let(Factory $factory) |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->beConstructedWith($factory, new Collection()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function it_is_initializable() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$this->shouldHaveType(Extended::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(['extends' => 'my_dictionary'])->shouldReturn(true); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_creates_a_dictionary($factory, Dictionary $initialDictionary, Dictionary $extendsDictionary) |
36
|
|
|
{ |
37
|
|
|
$initialDictionary->getName()->willReturn('initial_dictionary'); |
38
|
|
|
$initialDictionary->getIterator()->willReturn(new \ArrayIterator(['foo1', 'foo2'])); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$extendsDictionary->getName()->willReturn('extends_dictionary'); |
41
|
|
|
$extendsDictionary->getIterator()->willReturn(new \ArrayIterator(['bar1', 'bar2', 'bar3'])); |
42
|
|
|
|
43
|
|
|
$dictionaries = new Collection($initialDictionary->getWrappedObject(), $extendsDictionary->getWrappedObject()); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$this->beConstructedWith($factory, $dictionaries); |
46
|
|
|
|
47
|
|
|
$config = [ |
48
|
|
|
'content' => ['bar1', 'bar2', 'bar3'], |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$factory->create('yolo', $config)->willReturn($extendsDictionary); |
52
|
|
|
|
53
|
|
|
$config = array_merge($config, ['extends' => 'initial_dictionary']); |
54
|
|
|
$factory->supports($config)->willReturn(true); |
55
|
|
|
|
56
|
|
|
$dictionary = $this->create('yolo', $config); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$dictionary->getName()->shouldBe('yolo'); |
59
|
|
|
$dictionary->getValues()->shouldBe(['foo1', 'foo2', 'bar1', 'bar2', 'bar3']); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.