RouteTest::testWithHandlerClosure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

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