mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-15 18:23:26 +03:00
Major overhaul
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ExceptionHandler implements \Pecee\Handler\IExceptionHandler
|
||||
class ExceptionHandler implements \Pecee\Handlers\IExceptionHandler
|
||||
{
|
||||
public function handleError(\Pecee\Http\Request $request, \Pecee\SimpleRouter\RouterEntry &$route = null, \Exception $error)
|
||||
{
|
||||
|
||||
@@ -79,13 +79,22 @@ class GroupTest extends PHPUnit_Framework_TestCase
|
||||
SimpleRouter::request()->setUri('/my/fancy/url/1');
|
||||
SimpleRouter::request()->setMethod('get');
|
||||
|
||||
// Test array name
|
||||
SimpleRouter::get('/my/fancy/url/1', 'DummyController@start', ['as' => 'fancy1']);
|
||||
SimpleRouter::get('/my/fancy/url/2', 'DummyController@start')->setAlias('fancy2');
|
||||
|
||||
// Test method name
|
||||
SimpleRouter::get('/my/fancy/url/2', 'DummyController@start')->setName('fancy2');
|
||||
|
||||
// Test multiple names
|
||||
SimpleRouter::get('/my/fancy/url/3', 'DummyController@start', ['as' => ['fancy3', 'fancy4']]);
|
||||
|
||||
SimpleRouter::start();
|
||||
|
||||
$this->assertTrue((SimpleRouter::getRoute('fancy1') === '/my/fancy/url/1/'));
|
||||
$this->assertTrue((SimpleRouter::getRoute('fancy2') === '/my/fancy/url/2/'));
|
||||
$this->assertEquals('/my/fancy/url/1/', SimpleRouter::getRoute('fancy1'));
|
||||
$this->assertEquals('/my/fancy/url/2/', SimpleRouter::getRoute('fancy2'));
|
||||
|
||||
$this->assertEquals('/my/fancy/url/3/', SimpleRouter::getRoute('fancy3'));
|
||||
$this->assertEquals('/my/fancy/url/3/', SimpleRouter::getRoute('fancy4'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ require_once 'Dummy/DummyController.php';
|
||||
require_once 'Dummy/Handler/ExceptionHandler.php';
|
||||
|
||||
use Pecee\SimpleRouter\SimpleRouter as SimpleRouter;
|
||||
use Pecee\SimpleRouter\Exceptions\NotFoundHttpException as NotFoundHttpException;
|
||||
|
||||
class RouterRouteTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -25,7 +26,7 @@ class RouterRouteTest extends PHPUnit_Framework_TestCase
|
||||
try {
|
||||
SimpleRouter::start();
|
||||
} catch (\Exception $e) {
|
||||
$found = ($e instanceof \Pecee\Exception\RouterException && $e->getCode() == 404);
|
||||
$found = ($e instanceof NotFoundHttpException && $e->getCode() == 404);
|
||||
}
|
||||
|
||||
$this->assertTrue($found);
|
||||
|
||||
@@ -10,8 +10,8 @@ class RouterUrlTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $result = false;
|
||||
|
||||
protected function getUrl($controller = null, $parameters = null, $getParams = null) {
|
||||
return SimpleRouter::getRoute($controller, $parameters, $getParams);
|
||||
protected function getUrl($name = null, $parameters = null, array $getParams = []) {
|
||||
return SimpleRouter::getRoute($name, $parameters, $getParams);
|
||||
}
|
||||
|
||||
public function testUrls()
|
||||
@@ -75,8 +75,8 @@ class RouterUrlTest extends PHPUnit_Framework_TestCase
|
||||
// Should match /funny/man/
|
||||
$this->assertEquals($this->getUrl('/funny/man'), '/funny/man/');
|
||||
|
||||
// Should match /?jackdaniels=true
|
||||
$this->assertEquals($this->getUrl('home', null, ['jackdaniels' => 'true']), '/?jackdaniels=true');
|
||||
// Should match /?jackdaniels=true&cola=yeah
|
||||
$this->assertEquals($this->getUrl('home', null, ['jackdaniels' => 'true', 'cola' => 'yeah']), '/?jackdaniels=true&cola=yeah');
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user