[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:
Simon Sessingø
2016-04-09 07:05:49 +02:00
parent 2f2c3ca3ca
commit fc4fd0edf1
9 changed files with 183 additions and 23 deletions

39
test/MiddlewareTest.php Normal file
View 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');
}
}