mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 02:03:38 +03:00
[FEATURE] Added ExceptionHandling functionality + tests.
- Somehow the ExceptionHandling functionality never really get implemented and/or got lost in translation, it's back whup! - Added some basic tests for Middleware + routing.
This commit is contained in:
39
test/MiddlewareTest.php
Normal file
39
test/MiddlewareTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once 'Dummy/DummyMiddleware.php';
|
||||
require_once 'Dummy/DummyController.php';
|
||||
|
||||
class MiddlewareTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function __construct() {
|
||||
// Initial setup
|
||||
$_SERVER['HTTP_HOST'] = 'example.com';
|
||||
$_SERVER['REQUEST_URI'] = '/my/test/url';
|
||||
$_SERVER['REQUEST_METHOD'] = 'get';
|
||||
}
|
||||
|
||||
public function testMiddlewareFound() {
|
||||
|
||||
\Pecee\Http\Request::getInstance()->setMethod('get');
|
||||
|
||||
$router = new \Pecee\SimpleRouter\RouterBase();
|
||||
|
||||
$route = new \Pecee\SimpleRouter\RouterRoute('/my/test/url', 'DummyController@start');
|
||||
$route->setRequestMethods(array(\Pecee\SimpleRouter\RouterRoute::REQUEST_TYPE_GET));
|
||||
$route->addSettings(['middleware' => 'DummyMiddleware']);
|
||||
$router->addRoute($route);
|
||||
|
||||
try {
|
||||
$router->routeRequest();
|
||||
}catch(Exception $e) {
|
||||
$this->assertTrue(($e instanceof MiddlewareLoadedException));
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception('Middleware not loaded');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user