Completed
Push — master ( c4d705...5571d6 )
by Filipe
03:31
created

RouteFactorySpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 65 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 39
loc 60
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * This file is part of slick/web_stack package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace spec\Slick\WebStack\Router\Builder;
11
12
use Aura\Router\Map;
13
use Aura\Router\Route;
14
use Slick\WebStack\Router\Builder\FactoryInterface;
15
use Slick\WebStack\Router\Builder\RouteFactory;
16
use PhpSpec\ObjectBehavior;
17
18
/**
19
 * RouteFactorySpec specs
20
 *
21
 * @package spec\Slick\WebStack\Router\Builder
22
 */
23
class RouteFactorySpec extends ObjectBehavior
24
{
25
    function it_is_initializable()
26
    {
27
        $this->shouldHaveType(RouteFactory::class);
28
    }
29
30
    function its_a_route_factory()
31
    {
32
        $this->shouldBeAnInstanceOf(FactoryInterface::class);
33
    }
34
35
    function it_parses_simple_route_definitions(
36
        Map $map,
37
        Route $route
38
    ) {
39
        $map->get('blog.read', '/blog/{id}')->willReturn($route);
40
        $this->parse('blog.read', '/blog/{id}', $map)->shouldBe($route);
41
        $map->get('blog.read', '/blog/{id}')->shouldHaveBeenCalled();
42
    }
43
44
    function it_can_parse_complex_route_definitions(
45
        Map $map,
46
        Route $route
47
    ) {
48
        $data = [
49
            'name' => 'blog.edit',
50
            'data' => [
51
                'method' => 'PUT',
52
                'allows' => ['POST'],
53
                'path' => '/blog/{id}/edit'
54
            ],
55
        ];
56
        $map->route($data['name'], $data['data']['path'])->willReturn($route);
57
        $this->parse($data['name'], $data['data'], $map)->shouldBe($route);
58
        $map->route($data['name'], $data['data']['path'])->shouldHaveBeenCalled();
59
        $route->allows(['PUT', 'POST'])->shouldHaveBeenCalled();
60
    }
61
62
    function it_can_add_all_known_route_properties(
63
        Map $map,
64
        Route $route
65
    ) {
66
        $data = [
67
            'name' => 'blog.edit',
68
            'data' => [
69
                'defaults' => [
70
                    'id' => null
71
                ],
72
                'host' => 'www.example.com',
73
                'path' => '/blog/{id}/edit',
74
                'allows' => ['GET', 'POST']
75
            ],
76
        ];
77
        $map->route($data['name'], $data['data']['path'])->willReturn($route);
78
        $this->parse($data['name'], $data['data'], $map)->shouldBe($route);
79
        $route->defaults($data['data']['defaults'])->shouldHaveBeenCalled();
80
        $route->host($data['data']['host'])->shouldHaveBeenCalled();
81
    }
82
}
83