Completed
Push — master ( 4c7b9c...e919dc )
by Kamil
21:11
created

SuiteFactorySpec   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
lcom 1
cbo 5
dl 0
loc 167
rs 10
c 2
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_suite_factory_interface() 0 4 1
A it_creates_a_new_empty_suite() 0 7 1
A it_creates_a_new_suite_with_fixtures() 0 20 1
A it_creates_a_new_suite_with_prioritized_fixtures() 0 20 1
A it_creates_a_new_suite_with_customized_fixture() 0 16 1
A it_creates_a_new_suite_with_listeners() 0 20 1
A it_creates_a_new_suite_with_prioritized_listeners() 0 20 1
A it_creates_a_new_suite_with_customized_listener() 0 16 1
A it_throws_an_exception_if_suite_options_does_not_have_fixtures() 0 4 1
A it_throws_an_exception_if_suite_options_does_not_have_listeners() 0 4 1
A it_throws_an_exception_if_fixture_does_not_have_options_defined() 0 6 1
A it_throws_an_exception_if_listener_does_not_have_options_defined() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Bundle\FixturesBundle\Suite;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
17
use Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistryInterface;
18
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
19
use Sylius\Bundle\FixturesBundle\Listener\ListenerRegistryInterface;
20
use Sylius\Bundle\FixturesBundle\Suite\SuiteFactory;
21
use Sylius\Bundle\FixturesBundle\Suite\SuiteFactoryInterface;
22
use Symfony\Component\Config\Definition\Processor;
23
24
/**
25
 * @mixin SuiteFactory
26
 *
27
 * @author Kamil Kokot <[email protected]>
28
 */
29
final class SuiteFactorySpec extends ObjectBehavior
30
{
31
    function let(FixtureRegistryInterface $fixtureRegistry, ListenerRegistryInterface $listenerRegistry, Processor $optionsProcessor)
32
    {
33
        $this->beConstructedWith($fixtureRegistry, $listenerRegistry, $optionsProcessor);
34
    }
35
36
    function it_is_initializable()
37
    {
38
        $this->shouldHaveType('Sylius\Bundle\FixturesBundle\Suite\SuiteFactory');
39
    }
40
41
    function it_implements_suite_factory_interface()
42
    {
43
        $this->shouldImplement(SuiteFactoryInterface::class);
44
    }
45
46
    function it_creates_a_new_empty_suite()
47
    {
48
        $suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => []]);
49
50
        $suite->getName()->shouldReturn('suite_name');
51
        $suite->getFixtures()->shouldGenerate();
52
    }
53
54
    function it_creates_a_new_suite_with_fixtures(
55
        FixtureRegistryInterface $fixtureRegistry,
56
        Processor $optionsProcessor,
57
        FixtureInterface $firstFixture,
58
        FixtureInterface $secondFixture
59
    ) {
60
        $fixtureRegistry->getFixture('first_fixture')->willReturn($firstFixture);
61
        $fixtureRegistry->getFixture('second_fixture')->willReturn($secondFixture);
62
63
        $optionsProcessor->processConfiguration($firstFixture, [[]])->willReturn([]);
64
        $optionsProcessor->processConfiguration($secondFixture, [[]])->willReturn([]);
65
66
        $suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
67
            'first_fixture' => ['options' => [[]]],
68
            'second_fixture' => ['options' => [[]]],
69
        ]]);
70
71
        $suite->getName()->shouldReturn('suite_name');
72
        $suite->getFixtures()->shouldGenerateKeys($firstFixture, $secondFixture);
73
    }
74
75
    function it_creates_a_new_suite_with_prioritized_fixtures(
76
        FixtureRegistryInterface $fixtureRegistry,
77
        Processor $optionsProcessor,
78
        FixtureInterface $fixture,
79
        FixtureInterface $higherPriorityFixture
80
    ) {
81
        $fixtureRegistry->getFixture('fixture')->willReturn($fixture);
82
        $fixtureRegistry->getFixture('higher_priority_fixture')->willReturn($higherPriorityFixture);
83
84
        $optionsProcessor->processConfiguration($fixture, [[]])->willReturn([]);
85
        $optionsProcessor->processConfiguration($higherPriorityFixture, [[]])->willReturn([]);
86
87
        $suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
88
            'fixture' => ['priority' => 5, 'options' => [[]]],
89
            'higher_priority_fixture' => ['priority' => 10, 'options' => [[]]],
90
        ]]);
91
92
        $suite->getName()->shouldReturn('suite_name');
93
        $suite->getFixtures()->shouldGenerateKeys($higherPriorityFixture, $fixture);
94
    }
95
96
    function it_creates_a_new_suite_with_customized_fixture(
97
        FixtureRegistryInterface $fixtureRegistry,
98
        Processor $optionsProcessor,
99
        FixtureInterface $fixture
100
    ) {
101
        $fixtureRegistry->getFixture('fixture')->willReturn($fixture);
102
103
        $optionsProcessor->processConfiguration($fixture, [['fixture_option' => 'fixture_value']])->willReturn(['fixture_option' => 'fixture_value']);
104
105
        $suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
106
            'fixture' => ['options' => [['fixture_option' => 'fixture_value']]],
107
        ]]);
108
109
        $suite->getName()->shouldReturn('suite_name');
110
        $suite->getFixtures()->shouldGenerate([$fixture, ['fixture_option' => 'fixture_value']]);
111
    }
112
113
    function it_creates_a_new_suite_with_listeners(
114
        ListenerRegistryInterface $listenerRegistry,
115
        Processor $optionsProcessor,
116
        ListenerInterface $firstListener,
117
        ListenerInterface $secondListener
118
    ) {
119
        $listenerRegistry->getListener('first_listener')->willReturn($firstListener);
120
        $listenerRegistry->getListener('second_listener')->willReturn($secondListener);
121
122
        $optionsProcessor->processConfiguration($firstListener, [[]])->willReturn([]);
123
        $optionsProcessor->processConfiguration($secondListener, [[]])->willReturn([]);
124
125
        $suite = $this->createSuite('suite_name', ['fixtures' => [], 'listeners' => [
126
            'first_listener' => ['options' => [[]]],
127
            'second_listener' => ['options' => [[]]],
128
        ]]);
129
130
        $suite->getName()->shouldReturn('suite_name');
131
        $suite->getListeners()->shouldGenerateKeys($firstListener, $secondListener);
132
    }
133
134
    function it_creates_a_new_suite_with_prioritized_listeners(
135
        ListenerRegistryInterface $listenerRegistry,
136
        Processor $optionsProcessor,
137
        ListenerInterface $listener,
138
        ListenerInterface $higherPriorityListener
139
    ) {
140
        $listenerRegistry->getListener('listener')->willReturn($listener);
141
        $listenerRegistry->getListener('higher_priority_listener')->willReturn($higherPriorityListener);
142
143
        $optionsProcessor->processConfiguration($listener, [[]])->willReturn([]);
144
        $optionsProcessor->processConfiguration($higherPriorityListener, [[]])->willReturn([]);
145
146
        $suite = $this->createSuite('suite_name', ['fixtures' => [], 'listeners' => [
147
            'listener' => ['priority' => 5, 'options' => [[]]],
148
            'higher_priority_listener' => ['priority' => 10, 'options' => [[]]],
149
        ]]);
150
151
        $suite->getName()->shouldReturn('suite_name');
152
        $suite->getListeners()->shouldGenerateKeys($higherPriorityListener, $listener);
153
    }
154
155
    function it_creates_a_new_suite_with_customized_listener(
156
        ListenerRegistryInterface $listenerRegistry,
157
        Processor $optionsProcessor,
158
        ListenerInterface $listener
159
    ) {
160
        $listenerRegistry->getListener('listener')->willReturn($listener);
161
162
        $optionsProcessor->processConfiguration($listener, [['listener_option' => 'listener_value']])->willReturn(['listener_option' => 'listener_value']);
163
164
        $suite = $this->createSuite('suite_name', ['fixtures' => [], 'listeners' => [
165
            'listener' => ['options' => [['listener_option' => 'listener_value']]],
166
        ]]);
167
168
        $suite->getName()->shouldReturn('suite_name');
169
        $suite->getListeners()->shouldGenerate([$listener, ['listener_option' => 'listener_value']]);
170
    }
171
172
    function it_throws_an_exception_if_suite_options_does_not_have_fixtures()
173
    {
174
        $this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['listeners' => []]]);
175
    }
176
177
    function it_throws_an_exception_if_suite_options_does_not_have_listeners()
178
    {
179
        $this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['fixtures' => []]]);
180
    }
181
182
    function it_throws_an_exception_if_fixture_does_not_have_options_defined()
183
    {
184
        $this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['listeners' => [], 'fixtures' => [
185
            'fixture' => [],
186
        ]]]);
187
    }
188
189
    function it_throws_an_exception_if_listener_does_not_have_options_defined()
190
    {
191
        $this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['fixtures' => [], 'listeners' => [
192
            'listener' => [],
193
        ]]]);
194
    }
195
}
196