This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace KochTest\Router; |
||
4 | |||
5 | use Koch\Router\TargetRoute; |
||
6 | |||
7 | class TargetRouteTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @var TargetRoute |
||
11 | */ |
||
12 | protected $object; |
||
13 | |||
14 | /** |
||
15 | * Sets up the fixture, for example, opens a network connection. |
||
16 | * This method is called before a test is executed. |
||
17 | */ |
||
18 | protected function setUp() |
||
19 | { |
||
20 | $this->object = TargetRoute::instantiate(); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Tears down the fixture, for example, closes a network connection. |
||
25 | * This method is called after a test is executed. |
||
26 | */ |
||
27 | protected function tearDown() |
||
0 ignored issues
–
show
|
|||
28 | { |
||
29 | // static instance |
||
30 | $this->object->reset(); |
||
31 | unset($_SESSION); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @covers Koch\Router\TargetRoute::instantiate |
||
36 | */ |
||
37 | public function testInstantiate() |
||
38 | { |
||
39 | // Note: phpunit BUG |
||
40 | // $this->assertInstanceOf() autoloads the class, leading to redeclaration error |
||
41 | |||
42 | $tr = TargetRoute::instantiate(); |
||
43 | $this->assertTrue($tr instanceof TargetRoute); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @covers Koch\Router\TargetRoute::setFilename |
||
48 | * @covers Koch\Router\TargetRoute::getFilename |
||
49 | */ |
||
50 | public function testSetFilename() |
||
51 | { |
||
52 | //$this->object->setApplicationNamespace('KochTest/Fixtures/Application'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
78% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
53 | // test filename construction, if empty filename |
||
54 | $file1 = ''; |
||
55 | $this->object->setFilename($file1); |
||
56 | $this->assertEquals( |
||
57 | realpath(APPLICATION_MODULES_PATH . 'Index/Controller/IndexController.php'), |
||
58 | $this->object->getFilename() |
||
59 | ); |
||
60 | |||
61 | // setter test |
||
62 | $file2 = 'abc'; |
||
63 | $this->object->setFilename($file2); |
||
64 | $this->assertEquals($file2, $this->object->getFilename()); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @covers Koch\Router\TargetRoute::setClassname |
||
69 | * @covers Koch\Router\TargetRoute::getClassname |
||
70 | */ |
||
71 | public function testSetClassname() |
||
72 | { |
||
73 | $this->object->setApplicationNamespace('\KochTest\Fixtures\Application'); |
||
74 | |||
75 | // test filename construction, if empty filename |
||
76 | $class1 = ''; |
||
77 | $this->object->setClassname($class1); |
||
78 | $this->assertEquals( |
||
79 | '\KochTest\Fixtures\Application\Modules\Index\Controller\IndexController', |
||
80 | $this->object->getClassname() |
||
81 | ); |
||
82 | |||
83 | $class2 = 'abc'; |
||
84 | $this->object->setClassname($class2); |
||
85 | $this->assertEquals($class2, $this->object->getClassname()); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @covers Koch\Router\TargetRoute::getController |
||
90 | * @covers Koch\Router\TargetRoute::setController |
||
91 | */ |
||
92 | public function testGetController() |
||
93 | { |
||
94 | $class = ''; |
||
95 | $this->object->setController($class); |
||
96 | // if controller not set, it will be the default module name |
||
97 | $this->assertEquals('Index', $this->object->getController()); |
||
98 | |||
99 | $this->object->setController('aController'); |
||
100 | $this->assertEquals('AController', $this->object->getController()); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @covers Koch\Router\TargetRoute::setModule |
||
105 | * @covers Koch\Router\TargetRoute::getModule |
||
106 | */ |
||
107 | public function testSetModule() |
||
108 | { |
||
109 | $module = 'ABCModule'; |
||
110 | $this->object->setModule($module); |
||
111 | $this->assertEquals($module, $this->object->getModule()); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @covers Koch\Router\TargetRoute::setAction |
||
116 | * @covers Koch\Router\TargetRoute::getAction |
||
117 | */ |
||
118 | public function testSetAction() |
||
119 | { |
||
120 | $e = 'abc'; |
||
121 | $this->object->setAction($e); |
||
122 | $this->assertEquals($e, $this->object->getAction()); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @covers Koch\Router\TargetRoute::getActionNameWithoutPrefix |
||
127 | */ |
||
128 | public function testGetActionNameWithoutPrefix() |
||
129 | { |
||
130 | $this->object->setAction('myAction'); |
||
131 | $er = $this->object->getActionNameWithoutPrefix(); |
||
132 | $this->assertEquals($er, 'myAction'); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @covers Koch\Router\TargetRoute::setId |
||
137 | * @covers Koch\Router\TargetRoute::getId |
||
138 | */ |
||
139 | public function testSetId() |
||
140 | { |
||
141 | $id = '1'; |
||
142 | $this->object->setId($id); |
||
143 | $this->assertEquals($id, $this->object->getId()); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @covers Koch\Router\TargetRoute::setAction |
||
148 | * @covers Koch\Router\TargetRoute::getActionName |
||
149 | * @covers Koch\Router\TargetRoute::getMethod |
||
150 | */ |
||
151 | public function testGetActionName() |
||
152 | { |
||
153 | $this->object->setAction('MyAction'); |
||
154 | |||
155 | $this->assertEquals('actionMyAction', $this->object->getMethod()); |
||
156 | $this->assertEquals('actionMyAction', $this->object->getActionName()); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @covers Koch\Router\TargetRoute::setMethod |
||
161 | * @covers Koch\Router\TargetRoute::getMethod |
||
162 | * @covers Koch\Router\TargetRoute::getActionName |
||
163 | */ |
||
164 | public function testSetMethod() |
||
165 | { |
||
166 | $this->assertEquals('actionList', $this->object->getMethod()); |
||
167 | |||
168 | $this->object->setMethod('a-method'); |
||
169 | $this->assertEquals('a-method', $this->object->getActionName()); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * @covers Koch\Router\TargetRoute::setParameters |
||
174 | * @covers Koch\Router\TargetRoute::getParameters |
||
175 | */ |
||
176 | public function testSetParameters() |
||
0 ignored issues
–
show
testSetParameters uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
177 | { |
||
178 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
||
179 | |||
180 | $this->object->setParameters(['param1' => 'p1-value']); |
||
181 | |||
182 | $this->assertArrayHasKey('param1', $this->object->getParameters()); |
||
183 | |||
184 | unset($_SERVER['REQUEST_METHOD']); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @covers Koch\Router\TargetRoute::getParameters |
||
189 | */ |
||
190 | public function testGetParameters() |
||
0 ignored issues
–
show
testGetParameters uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
191 | { |
||
192 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
||
193 | |||
194 | // test for default array |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
38% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
195 | $er = $this->object->getParameters(); |
||
196 | $this->assertTrue(is_array($er)); |
||
197 | |||
198 | // test if values from $_POST array are automatically populated |
||
199 | // POST array is not populated on linux??? |
||
200 | /* $_SERVER['REQUEST_METHOD'] = 'POST'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
68% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
201 | $_POST['KEY1'] = 'VALUE1'; |
||
202 | |||
203 | $er = $this->object->getParameters(); |
||
204 | $this->assertTrue(is_array($er)); |
||
205 | $this->assertArrayHasKey('KEY1', $er); |
||
206 | |||
207 | unset($_SERVER['REQUEST_METHOD']); |
||
208 | unset($_POST['KEY1']); */ |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * @covers Koch\Router\TargetRoute::getFormat |
||
213 | */ |
||
214 | public function testGetFormat() |
||
215 | { |
||
216 | $er = $this->object->getFormat(); |
||
217 | $this->assertEquals($er, 'html'); |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @covers Koch\Router\TargetRoute::getRequestMethod |
||
222 | */ |
||
223 | public function testGetRequestMethod() |
||
0 ignored issues
–
show
testGetRequestMethod uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
224 | { |
||
225 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
||
226 | |||
227 | $er = $this->object->getRequestMethod(); |
||
228 | $this->assertEquals($er, 'GET'); |
||
229 | |||
230 | unset($_SERVER['REQUEST_METHOD']); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * @covers Koch\Router\TargetRoute::getLayoutMode |
||
235 | */ |
||
236 | public function testGetLayoutMode() |
||
237 | { |
||
238 | $this->object->setParameters(['layout' => true]); |
||
239 | $this->assertTrue($this->object->getLayoutMode()); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @covers Koch\Router\TargetRoute::getAjaxMode |
||
244 | * @depend Koch\Http\HttpRequest::isAjax |
||
245 | */ |
||
246 | public function testGetAjaxMode() |
||
247 | { |
||
248 | $this->assertFalse($this->object->getAjaxMode()); |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @covers Koch\Router\TargetRoute::setRenderEngine |
||
253 | * @covers Koch\Router\TargetRoute::getRenderEngine |
||
254 | */ |
||
255 | public function testSetRenderEngine() |
||
256 | { |
||
257 | $renderEngine = 'CopyCat'; |
||
258 | $this->object->setRenderEngine($renderEngine); |
||
259 | $this->assertEquals($renderEngine, $this->object->getRenderEngine()); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @covers Koch\Router\TargetRoute::getBackendTheme |
||
264 | */ |
||
265 | public function testGetBackendTheme() |
||
0 ignored issues
–
show
testGetBackendTheme uses the super-global variable $_SESSION which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
266 | { |
||
267 | $this->assertEquals('default', $this->object->getBackendTheme()); |
||
268 | |||
269 | $theme = 'A-Backend-Theme'; |
||
270 | $_SESSION['user']['backend_theme'] = $theme; |
||
271 | $this->assertEquals($theme, $this->object->getBackendTheme()); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @covers Koch\Router\TargetRoute::getFrontendTheme |
||
276 | */ |
||
277 | public function testGetFrontendTheme() |
||
0 ignored issues
–
show
testGetFrontendTheme uses the super-global variable $_SESSION which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
278 | { |
||
279 | $this->assertEquals('default', $this->object->getFrontendTheme()); |
||
280 | |||
281 | $theme = 'A-Frontend-Theme'; |
||
282 | $_SESSION['user']['frontend_theme'] = $theme; |
||
283 | $this->assertEquals($theme, $this->object->getFrontendTheme()); |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * @covers Koch\Router\TargetRoute::getThemeName |
||
288 | * @covers Koch\Router\TargetRoute::setThemeName |
||
289 | */ |
||
290 | public function testGetThemeName() |
||
291 | { |
||
292 | // default |
||
293 | // NOTICE! this assertion needs a TargetRoute and a $_Session reset |
||
294 | $this->assertEquals('default', $this->object->getThemeName()); |
||
295 | |||
296 | // explicitly set |
||
297 | $theme = 'MyTheme'; |
||
298 | $this->object->setThemeName($theme); |
||
299 | $this->assertEquals($theme, $this->object->getThemeName()); |
||
300 | $this->object->reset(); |
||
301 | |||
302 | $this->object->setModule('controlcenter'); |
||
303 | $this->assertEquals('default', $this->object->getThemeName()); |
||
304 | |||
305 | $this->object->setController('NewsAdminController'); |
||
306 | $this->assertEquals('default', $this->object->getThemeName()); |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * @covers Koch\Router\TargetRoute::getModRewriteStatus |
||
311 | */ |
||
312 | public function testGetModRewriteStatus() |
||
313 | { |
||
314 | $er = $this->object->getModRewriteStatus(); |
||
315 | $this->assertFalse($er); |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * @covers Koch\Router\TargetRoute::dispatchable |
||
320 | */ |
||
321 | public function testDispatchable() |
||
322 | { |
||
323 | $this->object->setApplicationNamespace('\KochTest\Fixtures\Application'); |
||
324 | |||
325 | $this->assertTrue($this->object->dispatchable()); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @covers Koch\Router\TargetRoute::setSegmentsToTargetRoute |
||
330 | */ |
||
331 | public function testSetSegmentsToTargetRoute() |
||
0 ignored issues
–
show
testSetSegmentsToTargetRoute uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
332 | { |
||
333 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
||
334 | |||
335 | $segments = []; |
||
336 | $er = $this->object->setSegmentsToTargetRoute($segments); |
||
337 | |||
338 | $this->assertTrue(is_object($er)); |
||
339 | |||
340 | unset($_SERVER['REQUEST_METHOD']); |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * @covers Koch\Router\TargetRoute::reset |
||
345 | */ |
||
346 | public function testReset() |
||
347 | { |
||
348 | $targetRouteParameters_BEFORE = $this->object->getRoute(); |
||
0 ignored issues
–
show
$targetRouteParameters_BEFORE does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
349 | $this->object->setID('1'); |
||
350 | $targetRouteParameters_MODDED = $this->object->getRoute(); |
||
0 ignored issues
–
show
$targetRouteParameters_MODDED does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
351 | $this->assertNotEquals($targetRouteParameters_MODDED, $targetRouteParameters_BEFORE); |
||
0 ignored issues
–
show
$targetRouteParameters_MODDED does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
352 | $this->object->reset(); |
||
353 | $targetRouteParameters_AFTER = $this->object->getRoute(); |
||
0 ignored issues
–
show
$targetRouteParameters_AFTER does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
354 | $this->assertEquals($targetRouteParameters_AFTER, $targetRouteParameters_BEFORE); |
||
0 ignored issues
–
show
$targetRouteParameters_AFTER does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
355 | } |
||
356 | |||
357 | /** |
||
358 | * @covers Koch\Router\TargetRoute::getRoute |
||
359 | */ |
||
360 | public function testGetRoute() |
||
361 | { |
||
362 | // this fetches the parameters array |
||
363 | $er = $this->object->getRoute(); |
||
364 | $this->assertTrue(is_array($er)); |
||
365 | } |
||
366 | } |
||
367 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: