ConventionalLoaderSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace spec\Knp\RadBundle\Routing\Loader;
4
5
use PhpSpec\ObjectBehavior;
6
use PhpSpec\Exception\Example\PendingException;
7
8
use InvalidArgumentException;
9
10
class ConventionalLoaderSpec extends ObjectBehavior
11
{
12
    /**
13
     * @param Symfony\Component\Config\FileLocatorInterface $locator
14
     * @param Knp\RadBundle\Routing\Loader\YamlParser       $yaml
15
     */
16
    function let($locator, $yaml)
17
    {
18
        $this->beConstructedWith($locator, $yaml);
19
20
        $locator->locate('routing.yml')->willReturn('yaml file');
21
    }
22
23
    function it_should_support_conventional_resources()
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_support_conventional_resources" is not in camel caps format
Loading history...
24
    {
25
        $this->supports('', 'rad_convention')->shouldReturn(true);
26
    }
27
28
    function it_should_not_support_other_resources()
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_not_support_other_resources" is not in camel caps format
Loading history...
29
    {
30
        $this->supports('')->shouldNotReturn(true);
31
    }
32
33
    function it_should_load_simple_collection_by_conventions($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_simple_collection_by_conventions" is not in camel caps format
Loading history...
34
    {
35
        $yaml->parse('yaml file')->willReturn(array(
36
            'App:Cheeses' => null
37
        ));
38
39
        $routes = $this->load('routing.yml');
40
41
        $index = $routes->get('app_cheeses_index');
42
        $index->getPattern()->shouldReturn('/cheeses/');
43
        $index->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:index'));
44
        $index->getRequirements()->shouldReturn(array('_method' => 'GET'));
45
46
        $new = $routes->get('app_cheeses_new');
47
        $new->getPattern()->shouldReturn('/cheeses/new');
48
        $new->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:new'));
49
        $new->getRequirements()->shouldReturn(array('_method' => 'GET'));
50
51
        $new = $routes->get('app_cheeses_create');
52
        $new->getPattern()->shouldReturn('/cheeses/');
53
        $new->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:new'));
54
        $new->getRequirements()->shouldReturn(array('_method' => 'POST'));
55
56
        $show = $routes->get('app_cheeses_show');
57
        $show->getPattern()->shouldReturn('/cheeses/{id}');
58
        $show->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:show'));
59
        $show->getRequirements()->shouldReturn(array('_method' => 'GET'));
60
61
        $edit = $routes->get('app_cheeses_edit');
62
        $edit->getPattern()->shouldReturn('/cheeses/{id}/edit');
63
        $edit->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:edit'));
64
        $edit->getRequirements()->shouldReturn(array('_method' => 'GET'));
65
66
        $edit = $routes->get('app_cheeses_update');
67
        $edit->getPattern()->shouldReturn('/cheeses/{id}');
68
        $edit->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:edit'));
69
        $edit->getRequirements()->shouldReturn(array('_method' => 'PUT'));
70
71
        $delete = $routes->get('app_cheeses_delete');
72
        $delete->getPattern()->shouldReturn('/cheeses/{id}');
73
        $delete->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:delete'));
74
        $delete->getRequirements()->shouldReturn(array('_method' => 'DELETE'));
75
76
        $routes->shouldHaveCount(7);
77
    }
78
79
    function it_should_load_collections_with_custom_prefix($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_collections_with_custom_prefix" is not in camel caps format
Loading history...
80
    {
81
        $yaml->parse('yaml file')->willReturn(array(
82
            'App:Cheeses' => '/custom/prefix'
83
        ));
84
85
        $routes = $this->load('routing.yml');
86
87
        $index = $routes->get('app_cheeses_index');
88
        $index->getPattern()->shouldReturn('/custom/prefix/');
89
        $index->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:index'));
90
        $index->getRequirements()->shouldReturn(array('_method' => 'GET'));
91
92
        $new = $routes->get('app_cheeses_new');
93
        $new->getPattern()->shouldReturn('/custom/prefix/new');
94
        $new->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:new'));
95
        $new->getRequirements()->shouldReturn(array('_method' => 'GET'));
96
97
        $new = $routes->get('app_cheeses_create');
98
        $new->getPattern()->shouldReturn('/custom/prefix/');
99
        $new->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:new'));
100
        $new->getRequirements()->shouldReturn(array('_method' => 'POST'));
101
102
        $show = $routes->get('app_cheeses_show');
103
        $show->getPattern()->shouldReturn('/custom/prefix/{id}');
104
        $show->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:show'));
105
        $show->getRequirements()->shouldReturn(array('_method' => 'GET'));
106
107
        $edit = $routes->get('app_cheeses_edit');
108
        $edit->getPattern()->shouldReturn('/custom/prefix/{id}/edit');
109
        $edit->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:edit'));
110
        $edit->getRequirements()->shouldReturn(array('_method' => 'GET'));
111
112
        $edit = $routes->get('app_cheeses_update');
113
        $edit->getPattern()->shouldReturn('/custom/prefix/{id}');
114
        $edit->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:edit'));
115
        $edit->getRequirements()->shouldReturn(array('_method' => 'PUT'));
116
117
        $delete = $routes->get('app_cheeses_delete');
118
        $delete->getPattern()->shouldReturn('/custom/prefix/{id}');
119
        $delete->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:delete'));
120
        $delete->getRequirements()->shouldReturn(array('_method' => 'DELETE'));
121
122
        $routes->shouldHaveCount(7);
123
    }
124
125
    function it_should_load_collections_with_specified_actions($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_collections_with_specified_actions" is not in camel caps format
Loading history...
126
    {
127
        $yaml->parse('yaml file')->willReturn(array(
128
            'App:Cheeses' => array(
129
                'prefix'      => '/custom/prefix',
130
                'resources'   => array('show', 'bam'),
131
                'collections' => array('index', 'paf'),
132
            )
133
        ));
134
135
        $routes = $this->load('routing.yml');
136
137
        $index = $routes->get('app_cheeses_index');
138
        $index->getPattern()->shouldReturn('/custom/prefix/');
139
        $index->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:index'));
140
        $index->getRequirements()->shouldReturn(array('_method' => 'GET'));
141
142
        $paf = $routes->get('app_cheeses_paf');
143
        $paf->getPattern()->shouldReturn('/custom/prefix/paf');
144
        $paf->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:paf'));
145
        $paf->getRequirements()->shouldReturn(array('_method' => 'GET'));
146
147
        $show = $routes->get('app_cheeses_show');
148
        $show->getPattern()->shouldReturn('/custom/prefix/{id}');
149
        $show->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:show'));
150
        $show->getRequirements()->shouldReturn(array('_method' => 'GET'));
151
152
        $bam = $routes->get('app_cheeses_bam');
153
        $bam->getPattern()->shouldReturn('/custom/prefix/{id}/bam');
154
        $bam->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:bam'));
155
        $bam->getRequirements()->shouldReturn(array('_method' => 'PUT'));
156
157
        $routes->shouldHaveCount(4);
158
    }
159
160
    function it_should_load_collections_with_specified_action_patterns($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_collections_with_specified_action_patterns" is not in camel caps format
Loading history...
161
    {
162
        $yaml->parse('yaml file')->willReturn(array(
163
            'App:Cheeses' => array(
164
                'prefix'    => '/custom/prefix',
165
                'resources' => array(
166
                    'show' => '/please/{id}/show',
167
                    'bam'  => '/please/{id}/bam',
168
                ),
169
                'collections' => array(
170
                    'index'  => '/list',
171
                    'paf'    => '/ouch',
172
                )
173
            )
174
        ));
175
176
        $routes = $this->load('routing.yml');
177
178
        $index = $routes->get('app_cheeses_index');
179
        $index->getPattern()->shouldReturn('/custom/prefix/list');
180
        $index->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:index'));
181
        $index->getRequirements()->shouldReturn(array('_method' => 'GET'));
182
183
        $paf = $routes->get('app_cheeses_paf');
184
        $paf->getPattern()->shouldReturn('/custom/prefix/ouch');
185
        $paf->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:paf'));
186
        $paf->getRequirements()->shouldReturn(array('_method' => 'GET'));
187
188
        $show = $routes->get('app_cheeses_show');
189
        $show->getPattern()->shouldReturn('/custom/prefix/please/{id}/show');
190
        $show->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:show'));
191
        $show->getRequirements()->shouldReturn(array('_method' => 'GET'));
192
193
        $bam = $routes->get('app_cheeses_bam');
194
        $bam->getPattern()->shouldReturn('/custom/prefix/please/{id}/bam');
195
        $bam->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:bam'));
196
        $bam->getRequirements()->shouldReturn(array('_method' => 'PUT'));
197
198
        $routes->shouldHaveCount(4);
199
    }
200
201
    function it_should_load_collections_with_custom_parameters($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_collections_with_custom_parameters" is not in camel caps format
Loading history...
202
    {
203
        $yaml->parse('yaml file')->willReturn(array(
204
            'App:Cheeses' => array(
205
                'prefix'    => '/custom/prefix',
206
                'resources' => array(
207
                    'show' => '/please/{id}/show',
208
                    'bam'  => array(
209
                        'pattern'      => '/please/{id}/bam',
210
                        'requirements' => array('_method' => 'GET'),
211
                        'defaults'     => array('_is_secured' => true)
212
                    ),
213
                ),
214
                'collections' => array(
215
                    'index'  => '/list',
216
                    'paf'    => array(
217
                        'pattern'      => '/pif-paf',
218
                        'requirements' => array('_method' => 'POST'),
219
                        'defaults'     => array('_top_menu' => 'guns')
220
                    ),
221
                )
222
            )
223
        ));
224
225
        $routes = $this->load('routing.yml');
226
227
        $index = $routes->get('app_cheeses_index');
228
        $index->getPattern()->shouldReturn('/custom/prefix/list');
229
        $index->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:index'));
230
        $index->getRequirements()->shouldReturn(array('_method' => 'GET'));
231
232
        $paf = $routes->get('app_cheeses_paf');
233
        $paf->getPattern()->shouldReturn('/custom/prefix/pif-paf');
234
        $paf->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:paf', '_top_menu' => 'guns'));
235
        $paf->getRequirements()->shouldReturn(array('_method' => 'POST'));
236
237
        $show = $routes->get('app_cheeses_show');
238
        $show->getPattern()->shouldReturn('/custom/prefix/please/{id}/show');
239
        $show->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:show'));
240
        $show->getRequirements()->shouldReturn(array('_method' => 'GET'));
241
242
        $bam = $routes->get('app_cheeses_bam');
243
        $bam->getPattern()->shouldReturn('/custom/prefix/please/{id}/bam');
244
        $bam->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:bam', '_is_secured' => true));
245
        $bam->getRequirements()->shouldReturn(array('_method' => 'GET'));
246
247
        $routes->shouldHaveCount(4);
248
    }
249
250
    function it_should_merge_defaults_and_requirements_into_child_routes($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_merge_defaults_and_requirements_into_child_routes" is not in camel caps format
Loading history...
251
    {
252
        $yaml->parse('yaml file')->willReturn(array(
253
            'App:Cheeses' => array(
254
                'prefix'       => '/custom/prefix',
255
                'defaults'     => array('_cheeses_filter' => 'french'),
256
                'requirements' => array('_format' => 'html|xml'),
257
258
                'resources' => array(
259
                    'defaults'     => array('_is_secured' => true),
260
                    'requirements' => array('id' => '\\d+'),
261
262
                    'show' => '/please/{id}/show',
263
                    'bam'  => array(
264
                        'pattern'      => '/please/{id}/bam',
265
                        'requirements' => array('_method' => 'POST')
266
                    ),
267
                ),
268
                'collections' => array(
269
                    'defaults'     => array('_top_menu' => 'guns'),
270
                    'requirements' => array('_stuff' => 'DELETE'),
271
272
                    'index'  => '/list',
273
                    'paf'    => '/pif-paf'
274
                )
275
            )
276
        ));
277
278
        $routes = $this->load('routing.yml');
279
280
        $index = $routes->get('app_cheeses_index');
281
        $index->getPattern()->shouldReturn('/custom/prefix/list');
282
        $index->getDefaults()->shouldReturn(array(
283
            '_cheeses_filter' => 'french',
284
            '_top_menu'       => 'guns',
285
            '_controller'     => 'App:Cheeses:index',
286
        ));
287
        $index->getRequirements()->shouldReturn(array(
288
            '_format' => 'html|xml',
289
            '_stuff'  => 'DELETE',
290
            '_method' => 'GET',
291
        ));
292
293
        $paf = $routes->get('app_cheeses_paf');
294
        $paf->getPattern()->shouldReturn('/custom/prefix/pif-paf');
295
        $paf->getDefaults()->shouldReturn(array(
296
            '_cheeses_filter' => 'french',
297
            '_top_menu'       => 'guns',
298
            '_controller'     => 'App:Cheeses:paf',
299
        ));
300
        $paf->getRequirements()->shouldReturn(array(
301
            '_format' => 'html|xml',
302
            '_stuff'  => 'DELETE',
303
            '_method' => 'GET',
304
        ));
305
306
        $show = $routes->get('app_cheeses_show');
307
        $show->getPattern()->shouldReturn('/custom/prefix/please/{id}/show');
308
        $show->getDefaults()->shouldReturn(array(
309
            '_cheeses_filter' => 'french',
310
            '_is_secured'     => true,
311
            '_controller'     => 'App:Cheeses:show',
312
        ));
313
        $show->getRequirements()->shouldReturn(array(
314
            '_format' => 'html|xml',
315
            'id'      => '\\d+',
316
            '_method' => 'GET',
317
        ));
318
319
        $bam = $routes->get('app_cheeses_bam');
320
        $bam->getPattern()->shouldReturn('/custom/prefix/please/{id}/bam');
321
        $bam->getDefaults()->shouldReturn(array(
322
            '_cheeses_filter' => 'french',
323
            '_is_secured'     => true,
324
            '_controller'     => 'App:Cheeses:bam',
325
        ));
326
        $bam->getRequirements()->shouldReturn(array(
327
            '_format' => 'html|xml',
328
            'id'      => '\\d+',
329
            '_method' => 'POST',
330
        ));
331
332
        $routes->shouldHaveCount(4);
333
    }
334
335
    function it_should_load_simple_routes_with_pattern($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_simple_routes_with_pattern" is not in camel caps format
Loading history...
336
    {
337
        $yaml->parse('yaml file')->willReturn(array(
338
            'App:Cheeses:list' => '/cheeses/{id}/list'
339
        ));
340
341
        $routes = $this->load('routing.yml');
342
343
        $list = $routes->get('app_cheeses_list');
344
        $list->getPattern()->shouldReturn('/cheeses/{id}/list');
345
        $list->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:list'));
346
        $list->getRequirements()->shouldReturn(array('_method' => 'GET'));
347
348
        $routes->shouldHaveCount(1);
349
    }
350
351
    function it_should_load_simple_routes_with_params($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_load_simple_routes_with_params" is not in camel caps format
Loading history...
352
    {
353
        $yaml->parse('yaml file')->willReturn(array(
354
            'App:Cheeses:list' => array(
355
                'pattern'  => '/cheeses/list-cheeses',
356
                'defaults' => array('_menu' => 'list')
357
            )
358
        ));
359
360
        $routes = $this->load('routing.yml');
361
362
        $list = $routes->get('app_cheeses_list');
363
        $list->getPattern()->shouldReturn('/cheeses/list-cheeses');
364
        $list->getDefaults()->shouldReturn(array('_controller' => 'App:Cheeses:list', '_menu' => 'list'));
365
        $list->getRequirements()->shouldReturn(array('_method' => 'GET'));
366
367
        $routes->shouldHaveCount(1);
368
    }
369
370
    function it_should_create_proper_route_for_namespaced_controller($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_create_proper_route_for_namespaced_controller" is not in camel caps format
Loading history...
371
    {
372
        $yaml->parse('yaml file')->willReturn(array(
373
            'App:Admin\Cheeses:list' => '/admin/cheeses/list-cheeses'
374
        ));
375
376
        $routes = $this->load('routing.yml');
377
378
        $list = $routes->get('app_admin_cheeses_list');
379
        $list->getPattern()->shouldReturn('/admin/cheeses/list-cheeses');
380
381
        $routes->shouldHaveCount(1);
382
    }
383
384
    function it_should_generate_proper_prefix_for_namespaced_controller($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_generate_proper_prefix_for_namespaced_controller" is not in camel caps format
Loading history...
385
    {
386
        $yaml->parse('yaml file')->willReturn(array(
387
            'App:Admin\Cheeses' => null
388
        ));
389
390
        $routes = $this->load('routing.yml');
391
392
        $index = $routes->get('app_admin_cheeses_index');
393
        $index->getPattern()->shouldReturn('/admin/cheeses/');
394
        $index->getDefaults()->shouldReturn(array('_controller' => 'App:Admin\Cheeses:index'));
395
        $index->getRequirements()->shouldReturn(array('_method' => 'GET'));
396
397
        $routes->shouldHaveCount(7);
398
    }
399
400
    function it_should_properly_transform_camel_cased_classes_and_groups($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_properly_transform_camel_cased_classes_and_groups" is not in camel caps format
Loading history...
401
    {
402
        $yaml->parse('yaml file')->willReturn(array(
403
            'SuperAppBundle:AdminControllers\Cheeses' => null
404
        ));
405
406
        $routes = $this->load('routing.yml');
407
        $routes->get('superAppBundle_adminControllers_cheeses_index')->shouldNotReturn(null);
408
    }
409
410
    function it_should_use_classic_loader_scheme_for_basic_routes($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_use_classic_loader_scheme_for_basic_routes" is not in camel caps format
Loading history...
411
    {
412
        $yaml->parse('yaml file')->willReturn(array(
413
            'blog_show' => array(
414
                'pattern'  => '/blog/{slug}',
415
                'defaults' => array('_controller' => 'AcmeBlogBundle:Blog:show'),
416
            ),
417
        ));
418
419
        $routes = $this->load('routing.yml');
420
        $route  = $routes->get('blog_show');
421
422
        $route->shouldNotBe(null);
423
        $route->getPattern()->shouldReturn('/blog/{slug}');
424
        $route->getDefaults()->shouldReturn(array('_controller' => 'AcmeBlogBundle:Blog:show'));
425
    }
426
427
    function it_should_throw_exception_if_unsupported_controller_route_param_provided($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_throw_exception_if_unsupported_controller_route_param_provided" is not in camel caps format
Loading history...
428
    {
429
        $yaml->parse('yaml file')->willReturn(array(
430
            'App:Admin\Cheeses' => array(
431
                'unsopported_key' => true
432
            )
433
        ));
434
435
        $this->shouldThrow(new InvalidArgumentException(
436
            '`unsopported_key` parameter is not supported by `App:Admin\Cheeses` controller route. Use one of [prefix, defaults, requirements, options, collections, resources].'
437
        ))->duringLoad('routing.yml');
438
    }
439
440
    function it_should_throw_exception_if_unsupported_action_route_param_provided($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_throw_exception_if_unsupported_action_route_param_provided" is not in camel caps format
Loading history...
441
    {
442
        $yaml->parse('yaml file')->willReturn(array(
443
            'App:Admin\Cheeses:show' => array(
444
                'unsopported_key' => true
445
            )
446
        ));
447
448
        $this->shouldThrow(new InvalidArgumentException(
449
            '`unsopported_key` parameter is not supported by `App:Admin\Cheeses:show` action route. Use one of [pattern, defaults, requirements, options, methods].'
450
        ))->duringLoad('routing.yml');
451
    }
452
453
    function it_should_throw_exception_if_user_uses_pattern_key_instead_of_prefix($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_throw_exception_if_user_uses_pattern_key_instead_of_prefix" is not in camel caps format
Loading history...
454
    {
455
        $yaml->parse('yaml file')->willReturn(array(
456
            'App:Cheeses' => array(
457
                'pattern' => '/custom/prefix'
458
            )
459
        ));
460
461
        $this->shouldThrow(new InvalidArgumentException(
462
            'The `pattern` is only supported for actions, if you want to prefix all the routes of the controller, use `prefix` instead.'
463
        ))->duringLoad('routing.yml');
464
    }
465
466
    function it_should_not_fail_when_loading_empty_resource($yaml)
0 ignored issues
show
Coding Style introduced by
Method name "ConventionalLoaderSpec::it_should_not_fail_when_loading_empty_resource" is not in camel caps format
Loading history...
467
    {
468
        $yaml->parse('yaml file')->willReturn(null);
469
470
        $routes = $this->load('routing.yml');
471
        $routes->shouldHaveCount(0);
472
    }
473
}
474