1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-server |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Server |
8
|
|
|
* @subpackage Apparat\Server\Tests |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Apparat\Server\Tests; |
38
|
|
|
|
39
|
|
|
use Apparat\Server\Ports\Route\Route; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Route test |
43
|
|
|
* |
44
|
|
|
* @package Apparat\Server |
45
|
|
|
* @subpackage Apparat\Server\Tests |
46
|
|
|
*/ |
47
|
|
|
class RouteTest extends AbstractServerTest |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* Test empty route verbs |
51
|
|
|
* |
52
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
53
|
|
|
* @expectedExceptionCode 1464520768 |
54
|
|
|
*/ |
55
|
|
|
public function testEmptyRouteVerbs() |
56
|
|
|
{ |
57
|
|
|
new Route('', 'name', 'path', 'action'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test invalid route verb |
62
|
|
|
* |
63
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
64
|
|
|
* @expectedExceptionCode 1464520896 |
65
|
|
|
*/ |
66
|
|
|
public function testInvalidRouteVerb() |
67
|
|
|
{ |
68
|
|
|
new Route('INVALID', 'name', 'path', 'action'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test empty route name |
73
|
|
|
* |
74
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
75
|
|
|
* @expectedExceptionCode 1464521013 |
76
|
|
|
*/ |
77
|
|
|
public function testEmptyRouteName() |
78
|
|
|
{ |
79
|
|
|
new Route(Route::GET, '', 'path', 'action'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test empty route path |
84
|
|
|
* |
85
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
86
|
|
|
* @expectedExceptionCode 1464521073 |
87
|
|
|
*/ |
88
|
|
|
public function testEmptyRoutePath() |
89
|
|
|
{ |
90
|
|
|
new Route(Route::GET, 'test', '', 'action'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Test empty route action |
95
|
|
|
* |
96
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
97
|
|
|
* @expectedExceptionCode 1464521136 |
98
|
|
|
*/ |
99
|
|
|
public function testEmptyRouteAction() |
100
|
|
|
{ |
101
|
|
|
new Route(Route::GET, 'test', 'path', ''); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Test invalid route action class |
106
|
|
|
* |
107
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
108
|
|
|
* @expectedExceptionCode 1464521937 |
109
|
|
|
*/ |
110
|
|
|
public function testInvalidRouteActionClass() |
111
|
|
|
{ |
112
|
|
|
new Route(Route::GET, 'test', 'path', 'InvalidRouteActionClass'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Test invalid route action interface |
117
|
|
|
* |
118
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
119
|
|
|
* @expectedExceptionCode 1464522202 |
120
|
|
|
*/ |
121
|
|
|
public function testInvalidRouteActionInterface() |
122
|
|
|
{ |
123
|
|
|
new Route(Route::GET, 'test', 'path', \stdClass::class); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Test invalid route action |
128
|
|
|
* |
129
|
|
|
* @expectedException \Apparat\Server\Ports\Route\InvalidArgumentException |
130
|
|
|
* @expectedExceptionCode 1464521506 |
131
|
|
|
*/ |
132
|
|
|
public function testInvalidRouteAction() |
133
|
|
|
{ |
134
|
|
|
new Route(Route::GET, 'test', 'path', [true]); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Test the route setters |
139
|
|
|
*/ |
140
|
|
|
public function testRouteSetters() |
141
|
|
|
{ |
142
|
|
|
$route = new Route( |
143
|
|
|
Route::GET, |
144
|
|
|
'test', |
145
|
|
|
'path', |
146
|
|
|
function () { |
|
|
|
|
147
|
|
|
} |
148
|
|
|
); |
149
|
|
|
$route->setDefaults(['key' => 'value']); |
150
|
|
|
$route->setWildcard('wildcard'); |
151
|
|
|
$route->setHost('apparat.tools'); |
152
|
|
|
$route->setAccepts(['application/json']); |
153
|
|
|
$route->setVerbs([Route::POST]); |
154
|
|
|
$route->setSecure(true); |
155
|
|
|
$route->setAuth('credentials'); |
156
|
|
|
$route->setExtras(['key' => 'value']); |
157
|
|
|
$this->assertInstanceOf(Route::class, $route); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: