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\Factory; |
9
|
|
|
use Knp\DictionaryBundle\Dictionary\Factory\Aggregate; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
|
12
|
|
|
final class AggregateSpec extends ObjectBehavior |
13
|
|
|
{ |
14
|
|
|
function it_is_initializable() |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$this->shouldHaveType(Aggregate::class); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function it_is_a_factory() |
20
|
|
|
{ |
21
|
|
|
$this->shouldHaveType(Factory::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function it_supports_if_one_factory_supports(Factory $factory1, Factory $factory2, Factory $factory3) |
25
|
|
|
{ |
26
|
|
|
$this->addFactory($factory1); |
|
|
|
|
27
|
|
|
$this->addFactory($factory2); |
28
|
|
|
|
29
|
|
|
$factory1->supports([])->willReturn(false); |
30
|
|
|
$factory2->supports([])->willReturn(false); |
31
|
|
|
$factory3->supports([])->willReturn(true); |
32
|
|
|
|
33
|
|
|
$this->supports([])->shouldReturn(false); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->addFactory($factory3); |
36
|
|
|
|
37
|
|
|
$this->supports([])->shouldReturn(true); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_uses_its_factory_to_build_a_dictionary( |
41
|
|
|
Factory $factory1, |
42
|
|
|
Factory $factory2, |
43
|
|
|
Factory $factory3, |
44
|
|
|
Dictionary $dictionary |
45
|
|
|
) { |
46
|
|
|
$this->addFactory($factory1); |
47
|
|
|
$this->addFactory($factory2); |
48
|
|
|
$this->addFactory($factory3); |
49
|
|
|
|
50
|
|
|
$factory1->supports([])->willReturn(false); |
51
|
|
|
$factory2->supports([])->willReturn(false); |
52
|
|
|
$factory3->supports([])->willReturn(true); |
53
|
|
|
|
54
|
|
|
$factory3->create('yolo', [])->willReturn($dictionary); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->create('yolo', [])->shouldReturn($dictionary); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_throws_exception_if_no_factory_supports_the_config( |
60
|
|
|
Factory $factory1, |
61
|
|
|
Factory $factory2, |
62
|
|
|
Factory $factory3 |
63
|
|
|
) { |
64
|
|
|
$this->addFactory($factory1); |
65
|
|
|
$this->addFactory($factory2); |
66
|
|
|
$this->addFactory($factory3); |
67
|
|
|
|
68
|
|
|
$factory1->supports([])->willReturn(false); |
69
|
|
|
$factory2->supports([])->willReturn(false); |
70
|
|
|
$factory3->supports([])->willReturn(false); |
71
|
|
|
|
72
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('create', ['yolo', []]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.