mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
- 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.
39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?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');
|
|
|
|
}
|
|
|
|
|
|
|
|
} |