Test Failed
Push — master ( 0ee32e...41c938 )
by Dan
07:10
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\Router;
4
5
use Ds\Router\Route;
6
use Tests\Router\Helpers;
7
8
/**
9
 * Class RouteTest
10
 * @package Tests\Router
11
 */
12
class RouteTest extends \PHPUnit_Framework_TestCase
13
{
14
15
    /**
16
     * @var Route
17
     */
18
    public $route;
19
20
    /**
21
     * @var string
22
     */
23
    protected $expectedMethod = 'GET';
24
25
    /**
26
     * @var string
27
     */
28
    protected $expectedPattern = '/path';
29
30
    /**
31
     * @var string
32
     */
33
    protected $expectedHandler = 'handler';
34
35
    /**
36
     * @var array
37
     */
38
    protected $expectedNames = ['name-1','name-2'];
39
40
    /**
41
     * Route setUp.
42
     */
43
    public function setUp()
44
    {
45
        $this->route = new Route(
46
            $this->expectedMethod,
47
            $this->expectedPattern,
48
            $this->expectedHandler,
49
            $this->expectedNames
50
        );
51
    }
52
53
    /**
54
     * Test immutable Route::withMethod()
55
     */
56 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...
57
    {
58
        $expected = 'POST';
59
        $route = $this->route->withMethod($expected);
60
        $this->assertSame(
61
            $expected,
62
            Helpers\Reflection::getProperty(Route::class, 'method', $route)
63
        );
64
    }
65
66
    /**
67
     * Test immutable Route::withPattern()
68
     */
69 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...
70
    {
71
        $expected = '/my-pattern/foo';
72
        $route = $this->route->withPattern($expected);
73
        $this->assertSame(
74
            $expected,
75
            Helpers\Reflection::getProperty(Route::class, 'pattern', $route)
76
        );
77
    }
78
79
    /**
80
     *
81
     */
82
    public function testWithNames()
83
    {
84
        $expected = ['foo','bar','baz'];
85
        $route = $this->route->withNames($expected);
86
        $this->assertSame(
87
            $expected,
88
            Helpers\Reflection::getProperty(Route::class, 'names', $route)
89
        );
90
    }
91
92
    /**
93
     *
94
     */
95 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...
96
    {
97
        $expected = 'controller::class';
98
        $route = $this->route->withHandler($expected);
99
100
        $this->assertSame(
101
            $expected,
102
            Helpers\Reflection::getProperty(Route::class, 'handler', $route)
103
        );
104
    }
105
106
    /**
107
     *
108
     */
109 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...
110
    {
111
        $expected = function () {
112
            return 'closure';
113
        };
114
        $route = $this->route->withHandler($expected);
115
116
        $actual = Helpers\Reflection::getProperty(Route::class, 'handler', $route);
117
118
        $this->assertSame(
119
            $expected,
120
            $actual
121
        );
122
    }
123
124
    /**
125
     *
126
     */
127
    public function testGetMethod()
128
    {
129
        $this->assertEquals($this->expectedMethod, $this->route->getMethod());
130
    }
131
132
    /**
133
     *
134
     */
135
    public function testGetHandler()
136
    {
137
        $this->assertEquals($this->expectedHandler, $this->route->getHandler());
138
    }
139
140
    /**
141
     *
142
     */
143
    public function testGetHandlerTypeString()
144
    {
145
        $expected = 'string';
146
        $actual = $this->route->getHandlerType();
147
        $this->assertEquals($expected, $actual);
148
    }
149
150
    /**
151
     *
152
     */
153
    public function testGetHandlerTypeClosure()
154
    {
155
        $closure = function () {
156
        };
157
        $expected = 'object';
158
        $route = $this->route->withHandler($closure);
159
        $actual = $route->getHandlerType();
160
        $this->assertEquals($expected, $actual);
161
    }
162
163
    /**
164
     *
165
     */
166
    public function testGetPattern()
167
    {
168
        $this->assertEquals($this->expectedPattern, $this->route->getPattern());
169
    }
170
171
    /**
172
     *
173
     */
174
    public function testGetNames()
175
    {
176
        $this->assertEquals($this->expectedNames, $this->route->getNames());
177
    }
178
}
179