LoaderSpec   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 328
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 3
dl 0
loc 328
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_supports_rad_resource_type() 0 5 1
A it_generates_7_conventional_routes_by_default() 0 10 1
A it_generates_conventional_patterns() 0 16 1
B it_generates_conventional_controller_names() 0 44 1
B it_cascades_default_config() 0 24 1
B it_overrides_default_config_explicitly() 0 24 1
A its_controller_can_be_a_service() 0 16 1
A it_allows_to_add_new_routes() 0 17 1
A it_allows_to_limit_number_of_generated_routes() 0 13 1
A it_allows_to_disable_all_routes() 0 12 1
A it_allows_new_routes_to_be_configured() 0 17 1
A it_uses_pattern_as_default_string_value() 0 17 1
A it_can_be_prefixed() 0 20 1
A it_can_be_nested() 0 23 1
A its_controllers_can_be_nested() 0 22 1
B its_custom_controllers_should_not_be_nested() 0 25 1
1
<?php
2
3
namespace spec\Knp\RadBundle\Routing\Conventional;
4
5
use PhpSpec\ObjectBehavior;
6
use Symfony\Component\Config\FileLocatorInterface;
7
use Knp\RadBundle\Routing\Conventional\Config\Factory as Configs;
8
use Knp\RadBundle\Routing\Conventional\Config\Parser;
9
10
class LoaderSpec extends ObjectBehavior
11
{
12
    function let(FileLocatorInterface $locator, Parser $yaml)
0 ignored issues
show
Unused Code introduced by
The parameter $yaml is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14
        $locator->locate('routing.yml')->willReturn('yaml/file/path');
15
    }
16
17
    function it_supports_rad_resource_type($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_supports_rad_resource_type" is not in camel caps format
Loading history...
18
    {
19
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
20
        $this->supports('yaml/file/path', 'rad')->shouldReturn(true);
21
    }
22
23
    function it_generates_7_conventional_routes_by_default($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_generates_7_conventional_routes_by_default" is not in camel caps format
Loading history...
24
    {
25
        $yaml->parse('yaml/file/path')->willReturn(array(
26
            'App:Cheese' => null
27
        ));
28
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
29
        $collection = $this->load('routing.yml');
30
31
        $collection->shouldHaveCount(7);
32
    }
33
34
    function it_generates_conventional_patterns($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_generates_conventional_patterns" is not in camel caps format
Loading history...
35
    {
36
        $yaml->parse('yaml/file/path')->willReturn(array(
37
            'App:Cheese' => null
38
        ));
39
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
40
        $collection = $this->load('routing.yml');
41
42
        $collection->get('app_cheese_index')->getPattern()->shouldReturn('/cheese.{_format}');
43
        $collection->get('app_cheese_new')->getPattern()->shouldReturn('/cheese/new.{_format}');
44
        $collection->get('app_cheese_create')->getPattern()->shouldReturn('/cheese/new.{_format}');
45
        $collection->get('app_cheese_edit')->getPattern()->shouldReturn('/cheese/{id}/edit.{_format}');
46
        $collection->get('app_cheese_update')->getPattern()->shouldReturn('/cheese/{id}/edit.{_format}');
47
        $collection->get('app_cheese_show')->getPattern()->shouldReturn('/cheese/{id}.{_format}');
48
        $collection->get('app_cheese_delete')->getPattern()->shouldReturn('/cheese/{id}.{_format}');
49
    }
50
51
    function it_generates_conventional_controller_names($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_generates_conventional_controller_names" is not in camel caps format
Loading history...
52
    {
53
        $yaml->parse('yaml/file/path')->willReturn(array(
54
            'App:Cheese' => null
55
        ));
56
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
57
        $collection = $this->load('routing.yml');
58
59
        $collection->get('app_cheese_index')->getDefaults()->shouldReturn(array(
60
            '_controller' => 'App:Cheese:index',
61
            'view' => 'App:Cheese:index',
62
            '_format' => 'html',
63
        ));
64
        $collection->get('app_cheese_new')->getDefaults()->shouldReturn(array(
65
            '_controller' => 'App:Cheese:new',
66
            'view' => 'App:Cheese:new',
67
            '_format' => 'html',
68
        ));
69
        $collection->get('app_cheese_create')->getDefaults()->shouldReturn(array(
70
            '_controller' => 'App:Cheese:new',
71
            'view' => 'App:Cheese:create',
72
            '_format' => 'html',
73
        ));
74
        $collection->get('app_cheese_edit')->getDefaults()->shouldReturn(array(
75
            '_controller' => 'App:Cheese:edit',
76
            'view' => 'App:Cheese:edit',
77
            '_format' => 'html',
78
        ));
79
        $collection->get('app_cheese_update')->getDefaults()->shouldReturn(array(
80
            '_controller' => 'App:Cheese:edit',
81
            'view' => 'App:Cheese:update',
82
            '_format' => 'html',
83
        ));
84
        $collection->get('app_cheese_show')->getDefaults()->shouldReturn(array(
85
            '_controller' => 'App:Cheese:show',
86
            'view' => 'App:Cheese:show',
87
            '_format' => 'html',
88
        ));
89
        $collection->get('app_cheese_delete')->getDefaults()->shouldReturn(array(
90
            '_controller' => 'App:Cheese:delete',
91
            'view' => 'App:Cheese:delete',
92
            '_format' => 'html',
93
        ));
94
    }
95
96
    function it_cascades_default_config($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_cascades_default_config" is not in camel caps format
Loading history...
97
    {
98
        $yaml->parse('yaml/file/path')->willReturn(array(
99
            'App:Cheese' => array(
100
                'defaults' => array(
101
                    '_resources' => array(
102
                        'object' => array('expr' => "request.get('id')"),
103
                    ),
104
                ),
105
                'requirements' => array('_format' => 'html'),
106
            ),
107
        ));
108
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
109
        $collection = $this->load('routing.yml');
110
111
        $collection->get('app_cheese_index')->getDefaults()->shouldReturn(array(
112
            '_controller' => 'App:Cheese:index',
113
            'view' => 'App:Cheese:index',
114
            '_resources' => array(
115
                'object' => array('expr' => "request.get('id')"),
116
            ),
117
            '_format' => 'html',
118
        ));
119
    }
120
121
    function it_overrides_default_config_explicitly($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_overrides_default_config_explicitly" is not in camel caps format
Loading history...
122
    {
123
        $yaml->parse('yaml/file/path')->willReturn(array(
124
            'App:Cheese' => array(
125
                'defaults' => array(
126
                    '_resources' => array(
127
                        'object' => array('expr' => "request.get('id')"),
128
                    ),
129
                ),
130
                'index' => array(
131
                    'defaults' => array('_resources' => array()),
132
                ),
133
                'requirements' => array('_format' => 'html'),
134
            ),
135
        ));
136
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
137
        $collection = $this->load('routing.yml');
138
139
        $collection->get('app_cheese_index')->getDefaults()->shouldReturn(array(
140
            '_controller' => 'App:Cheese:index',
141
            'view' => 'App:Cheese:index',
142
            '_resources' => array(),
143
        ));
144
    }
145
146
    function its_controller_can_be_a_service($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::its_controller_can_be_a_service" is not in camel caps format
Loading history...
147
    {
148
        $yaml->parse('yaml/file/path')->willReturn(array(
149
            'App:Cheese' => array(
150
                'controller' => 'knp_rad.controller.crud_controller',
151
            ),
152
        ));
153
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
154
        $collection = $this->load('routing.yml');
155
156
        $collection->get('app_cheese_index')->getDefaults()->shouldReturn(array(
157
            '_controller' => 'knp_rad.controller.crud_controller:indexAction',
158
            'view' => 'App:Cheese:index',
159
            '_format' => 'html',
160
        ));
161
    }
162
163
    function it_allows_to_add_new_routes($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_allows_to_add_new_routes" is not in camel caps format
Loading history...
164
    {
165
        $yaml->parse('yaml/file/path')->willReturn(array(
166
            'App:Cheese' => array(
167
                'custom' => null,
168
            ),
169
        ));
170
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
171
        $collection = $this->load('routing.yml');
172
173
        $collection->get('app_cheese_custom')->getDefaults()->shouldReturn(array(
174
            '_controller' => 'App:Cheese:custom',
175
            'view' => 'App:Cheese:custom',
176
            '_format' => 'html',
177
        ));
178
        $collection->get('app_cheese_custom')->getPattern()->shouldReturn('/cheese/custom');
179
    }
180
181
    function it_allows_to_limit_number_of_generated_routes($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_allows_to_limit_number_of_generated_routes" is not in camel caps format
Loading history...
182
    {
183
        $yaml->parse('yaml/file/path')->willReturn(array(
184
            'App:Cheese' => array(
185
                'custom' => null,
186
                'elements' => array('index', 'show'),
187
            ),
188
        ));
189
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
190
        $collection = $this->load('routing.yml');
191
192
        $collection->shouldHaveCount(3);
193
    }
194
195
    function it_allows_to_disable_all_routes($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_allows_to_disable_all_routes" is not in camel caps format
Loading history...
196
    {
197
        $yaml->parse('yaml/file/path')->willReturn(array(
198
            'App:Cheese' => array(
199
                'elements' => array(),
200
            ),
201
        ));
202
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
203
        $collection = $this->load('routing.yml');
204
205
        $collection->shouldHaveCount(0);
206
    }
207
208
    function it_allows_new_routes_to_be_configured($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_allows_new_routes_to_be_configured" is not in camel caps format
Loading history...
209
    {
210
        $yaml->parse('yaml/file/path')->willReturn(array(
211
            'App:Cheese' => array(
212
                'custom' => array('controller' => 'a different one'),
213
            ),
214
        ));
215
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
216
        $collection = $this->load('routing.yml');
217
218
        $collection->get('app_cheese_custom')->getDefaults()->shouldReturn(array(
219
            '_controller' => 'a different one:customAction',
220
            'view' => 'App:Cheese:custom',
221
            '_format' => 'html',
222
        ));
223
        $collection->get('app_cheese_custom')->getPattern()->shouldReturn('/cheese/custom');
224
    }
225
226
    function it_uses_pattern_as_default_string_value($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_uses_pattern_as_default_string_value" is not in camel caps format
Loading history...
227
    {
228
        $yaml->parse('yaml/file/path')->willReturn(array(
229
            'App:Cheese' => array(
230
                'custom' => '/patt{ern}/de/ouf'
231
            ),
232
        ));
233
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
234
        $collection = $this->load('routing.yml');
235
236
        $collection->get('app_cheese_custom')->getDefaults()->shouldReturn(array(
237
            '_controller' => 'App:Cheese:custom',
238
            'view' => 'App:Cheese:custom',
239
            '_format' => 'html',
240
        ));
241
        $collection->get('app_cheese_custom')->getPattern()->shouldReturn('/cheese/patt{ern}/de/ouf');
242
    }
243
244
    public function it_can_be_prefixed($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_can_be_prefixed" is not in camel caps format
Loading history...
245
    {
246
        $yaml->parse('yaml/file/path')->willReturn(array(
247
            'App:Cheese' => array(
248
                'custom' => array(
249
                    'pattern' => '/patt{ern}/de/ouf',
250
                    'prefix' => 'test:sub',
251
                ),
252
            ),
253
        ));
254
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
255
        $collection = $this->load('routing.yml');
256
257
        $collection->get('app_cheese_custom')->getPattern()->shouldReturn('/sub/patt{ern}/de/ouf');
258
        $collection->get('app_cheese_custom')->getDefaults()->shouldReturn(array(
259
            '_controller' => 'App:Cheese:custom',
260
            'view' => 'App:Cheese:custom',
261
            '_format' => 'html',
262
        ));
263
    }
264
265
    public function it_can_be_nested($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::it_can_be_nested" is not in camel caps format
Loading history...
266
    {
267
        $yaml->parse('yaml/file/path')->willReturn(array(
268
            'App:Food' => array(
269
                'elements' => array('show'),
270
            ),
271
            'App:Cheese' => array(
272
                'parent' => 'App:Food',
273
                'elements' => array('show', 'index'),
274
            ),
275
            'App:Cantal' => array(
276
                'parent' => 'App:Cheese',
277
                'elements' => array('show', 'index'),
278
            ),
279
        ));
280
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
281
        $collection = $this->load('routing.yml');
282
283
        $collection->get('app_food_cheese_show')->getPattern()->shouldReturn('/food/{foodId}/cheese/{id}.{_format}');
284
        $collection->get('app_food_cheese_index')->getPattern()->shouldReturn('/food/{foodId}/cheese.{_format}');
285
286
        $collection->get('app_food_cheese_cantal_show')->getPattern()->shouldReturn('/food/{foodId}/cheese/{cheeseId}/cantal/{id}.{_format}');
287
    }
288
289
    public function its_controllers_can_be_nested($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::its_controllers_can_be_nested" is not in camel caps format
Loading history...
290
    {
291
        $yaml->parse('yaml/file/path')->willReturn(array(
292
            'App:Food' => array(
293
                'elements' => array('show'),
294
            ),
295
            'App:Cheese' => array(
296
                'parent' => 'App:Food',
297
                'elements' => array('show', 'index'),
298
            ),
299
            'App:Cantal' => array(
300
                'parent' => 'App:Cheese',
301
                'elements' => array('show', 'index'),
302
            ),
303
        ));
304
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
305
        $collection = $this->load('routing.yml');
306
307
        $collection->get('app_food_cheese_cantal_show')->getDefaults()
308
            ->shouldContain('App:Food/Cheese/Cantal:show')
309
        ;
310
    }
311
312
    public function its_custom_controllers_should_not_be_nested($locator, $yaml)
0 ignored issues
show
Coding Style introduced by
Method name "LoaderSpec::its_custom_controllers_should_not_be_nested" is not in camel caps format
Loading history...
313
    {
314
        $yaml->parse('yaml/file/path')->willReturn(array(
315
            'App:Food' => array(
316
                'controller' => 'app.controller.food',
317
                'elements' => array('show'),
318
            ),
319
            'App:Cheese' => array(
320
                'controller' => 'app.controller.food.cheese',
321
                'parent' => 'App:Food',
322
                'elements' => array('show', 'index'),
323
            ),
324
            'App:Cantal' => array(
325
                'controller' => 'app.controller.food.cheese.cantal',
326
                'parent' => 'App:Cheese',
327
                'elements' => array('show', 'index'),
328
            ),
329
        ));
330
        $this->beConstructedWith($locator, new Configs($yaml->getWrappedObject()));
331
        $collection = $this->load('routing.yml');
332
333
        $collection->get('app_food_cheese_cantal_show')->getDefaults()
334
            ->shouldContain('app.controller.food.cheese.cantal:showAction')
335
        ;
336
    }
337
}
338