Test Failed
Push — master ( 3e96d2...d4b731 )
by Dan
06:30
created

RouteTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 167
Duplicated Lines 25.15 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 4
dl 42
loc 167
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testWithMethod() 9 9 1
A testWithPattern() 9 9 1
A testWithNames() 0 9 1
A testWithHandlerString() 10 10 1
A testWithHandlerClosure() 14 14 1
A testGetMethod() 0 4 1
A testGetHandler() 0 4 1
A testGetHandlerTypeString() 0 6 1
A testGetHandlerTypeClosure() 0 9 1
A testGetPattern() 0 4 1
A testGetNames() 0 4 1

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
namespace Tests\Ds\Router;
4
5
use Ds\Router\Route;
6
7
/**
8
 * Class RouteTest
9
 * @package Tests\Ds\Router
10
 */
11
class RouteTest extends \PHPUnit_Framework_TestCase
12
{
13
14
    /**
15
     * @var Route
16
     */
17
    public $route;
18
19
    /**
20
     * @var string
21
     */
22
    protected $expectedMethod = 'GET';
23
24
    /**
25
     * @var string
26
     */
27
    protected $expectedPattern = '/path';
28
29
    /**
30
     * @var string
31
     */
32
    protected $expectedHandler = 'handler';
33
34
    /**
35
     * @var array
36
     */
37
    protected $expectedNames = ['name-1','name-2'];
38
39
    /**
40
     * Route setUp.
41
     */
42
    public function setUp()
43
    {
44
        $this->route = new Route(
45
            $this->expectedMethod,
46
            $this->expectedPattern,
47
            $this->expectedHandler,
48
            $this->expectedNames
49
        );
50
    }
51
52
    /**
53
     * Test immutable Route::withMethod()
54
     */
55 View Code Duplication
    public function testWithMethod()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $expected = 'POST';
58
        $route = $this->route->withMethod($expected);
59
        $this->assertSame(
60
            $expected,
61
            Helpers\Reflection::getProperty(Route::class, 'method', $route)
62
        );
63
    }
64
65
    /**
66
     * Test immutable Route::withPattern()
67
     */
68 View Code Duplication
    public function testWithPattern()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $expected = '/my-pattern/foo';
71
        $route = $this->route->withPattern($expected);
72
        $this->assertSame(
73
            $expected,
74
            Helpers\Reflection::getProperty(Route::class, 'pattern', $route)
75
        );
76
    }
77
78
    /**
79
     *
80
     */
81
    public function testWithNames()
82
    {
83
        $expected = ['foo','bar','baz'];
84
        $route = $this->route->withNames($expected);
85
        $this->assertSame(
86
            $expected,
87
            Helpers\Reflection::getProperty(Route::class, 'names', $route)
88
        );
89
    }
90
91
    /**
92
     *
93
     */
94 View Code Duplication
    public function testWithHandlerString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $expected = 'controller::class';
97
        $route = $this->route->withHandler($expected);
98
99
        $this->assertSame(
100
            $expected,
101
            Helpers\Reflection::getProperty(Route::class, 'handler', $route)
102
        );
103
    }
104
105
    /**
106
     *
107
     */
108 View Code Duplication
    public function testWithHandlerClosure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
    {
110
        $expected = function () {
111
            return 'closure';
112
        };
113
        $route = $this->route->withHandler($expected);
114
115
        $actual = Helpers\Reflection::getProperty(Route::class, 'handler', $route);
116
117
        $this->assertSame(
118
            $expected,
119
            $actual
120
        );
121
    }
122
123
    /**
124
     *
125
     */
126
    public function testGetMethod()
127
    {
128
        $this->assertEquals($this->expectedMethod, $this->route->getMethod());
129
    }
130
131
    /**
132
     *
133
     */
134
    public function testGetHandler()
135
    {
136
        $this->assertEquals($this->expectedHandler, $this->route->getHandler());
137
    }
138
139
    /**
140
     *
141
     */
142
    public function testGetHandlerTypeString()
143
    {
144
        $expected = 'string';
145
        $actual = $this->route->getHandlerType();
146
        $this->assertEquals($expected, $actual);
147
    }
148
149
    /**
150
     *
151
     */
152
    public function testGetHandlerTypeClosure()
153
    {
154
        $closure = function () {
155
        };
156
        $expected = 'object';
157
        $route = $this->route->withHandler($closure);
158
        $actual = $route->getHandlerType();
159
        $this->assertEquals($expected, $actual);
160
    }
161
162
    /**
163
     *
164
     */
165
    public function testGetPattern()
166
    {
167
        $this->assertEquals($this->expectedPattern, $this->route->getPattern());
168
    }
169
170
    /**
171
     *
172
     */
173
    public function testGetNames()
174
    {
175
        $this->assertEquals($this->expectedNames, $this->route->getNames());
176
    }
177
}
178