|
@@ -3,9 +3,10 @@
|
|
namespace FastRoute\Dispatcher;
|
|
namespace FastRoute\Dispatcher;
|
|
|
|
|
|
use FastRoute\RouteCollector;
|
|
use FastRoute\RouteCollector;
|
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
-abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
-
|
|
|
|
|
|
+abstract class DispatcherTest extends TestCase
|
|
|
|
+{
|
|
/**
|
|
/**
|
|
* Delegate dispatcher selection to child test classes
|
|
* Delegate dispatcher selection to child test classes
|
|
*/
|
|
*/
|
|
@@ -19,7 +20,8 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
/**
|
|
/**
|
|
* Set appropriate options for the specific Dispatcher class we're testing
|
|
* Set appropriate options for the specific Dispatcher class we're testing
|
|
*/
|
|
*/
|
|
- private function generateDispatcherOptions() {
|
|
|
|
|
|
+ private function generateDispatcherOptions()
|
|
|
|
+ {
|
|
return [
|
|
return [
|
|
'dataGenerator' => $this->getDataGeneratorClass(),
|
|
'dataGenerator' => $this->getDataGeneratorClass(),
|
|
'dispatcher' => $this->getDispatcherClass()
|
|
'dispatcher' => $this->getDispatcherClass()
|
|
@@ -29,7 +31,8 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
/**
|
|
/**
|
|
* @dataProvider provideFoundDispatchCases
|
|
* @dataProvider provideFoundDispatchCases
|
|
*/
|
|
*/
|
|
- public function testFoundDispatches($method, $uri, $callback, $handler, $argDict) {
|
|
|
|
|
|
+ public function testFoundDispatches($method, $uri, $callback, $handler, $argDict)
|
|
|
|
+ {
|
|
$dispatcher = \FastRoute\simpleDispatcher($callback, $this->generateDispatcherOptions());
|
|
$dispatcher = \FastRoute\simpleDispatcher($callback, $this->generateDispatcherOptions());
|
|
$info = $dispatcher->dispatch($method, $uri);
|
|
$info = $dispatcher->dispatch($method, $uri);
|
|
$this->assertSame($dispatcher::FOUND, $info[0]);
|
|
$this->assertSame($dispatcher::FOUND, $info[0]);
|
|
@@ -40,11 +43,12 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
/**
|
|
/**
|
|
* @dataProvider provideNotFoundDispatchCases
|
|
* @dataProvider provideNotFoundDispatchCases
|
|
*/
|
|
*/
|
|
- public function testNotFoundDispatches($method, $uri, $callback) {
|
|
|
|
|
|
+ public function testNotFoundDispatches($method, $uri, $callback)
|
|
|
|
+ {
|
|
$dispatcher = \FastRoute\simpleDispatcher($callback, $this->generateDispatcherOptions());
|
|
$dispatcher = \FastRoute\simpleDispatcher($callback, $this->generateDispatcherOptions());
|
|
$routeInfo = $dispatcher->dispatch($method, $uri);
|
|
$routeInfo = $dispatcher->dispatch($method, $uri);
|
|
- $this->assertFalse(isset($routeInfo[1]),
|
|
|
|
- "NOT_FOUND result must only contain a single element in the returned info array"
|
|
|
|
|
|
+ $this->assertArrayNotHasKey(1, $routeInfo,
|
|
|
|
+ 'NOT_FOUND result must only contain a single element in the returned info array'
|
|
);
|
|
);
|
|
$this->assertSame($dispatcher::NOT_FOUND, $routeInfo[0]);
|
|
$this->assertSame($dispatcher::NOT_FOUND, $routeInfo[0]);
|
|
}
|
|
}
|
|
@@ -52,11 +56,12 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
/**
|
|
/**
|
|
* @dataProvider provideMethodNotAllowedDispatchCases
|
|
* @dataProvider provideMethodNotAllowedDispatchCases
|
|
*/
|
|
*/
|
|
- public function testMethodNotAllowedDispatches($method, $uri, $callback, $availableMethods) {
|
|
|
|
|
|
+ public function testMethodNotAllowedDispatches($method, $uri, $callback, $availableMethods)
|
|
|
|
+ {
|
|
$dispatcher = \FastRoute\simpleDispatcher($callback, $this->generateDispatcherOptions());
|
|
$dispatcher = \FastRoute\simpleDispatcher($callback, $this->generateDispatcherOptions());
|
|
$routeInfo = $dispatcher->dispatch($method, $uri);
|
|
$routeInfo = $dispatcher->dispatch($method, $uri);
|
|
- $this->assertTrue(isset($routeInfo[1]),
|
|
|
|
- "METHOD_NOT_ALLOWED result must return an array of allowed methods at index 1"
|
|
|
|
|
|
+ $this->assertArrayHasKey(1, $routeInfo,
|
|
|
|
+ 'METHOD_NOT_ALLOWED result must return an array of allowed methods at index 1'
|
|
);
|
|
);
|
|
|
|
|
|
list($routedStatus, $methodArray) = $dispatcher->dispatch($method, $uri);
|
|
list($routedStatus, $methodArray) = $dispatcher->dispatch($method, $uri);
|
|
@@ -68,8 +73,9 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedExceptionMessage Cannot use the same placeholder "test" twice
|
|
* @expectedExceptionMessage Cannot use the same placeholder "test" twice
|
|
*/
|
|
*/
|
|
- public function testDuplicateVariableNameError() {
|
|
|
|
- \FastRoute\simpleDispatcher(function(RouteCollector $r) {
|
|
|
|
|
|
+ public function testDuplicateVariableNameError()
|
|
|
|
+ {
|
|
|
|
+ \FastRoute\simpleDispatcher(function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/foo/{test}/{test:\d+}', 'handler0');
|
|
$r->addRoute('GET', '/foo/{test}/{test:\d+}', 'handler0');
|
|
}, $this->generateDispatcherOptions());
|
|
}, $this->generateDispatcherOptions());
|
|
}
|
|
}
|
|
@@ -78,8 +84,9 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedExceptionMessage Cannot register two routes matching "/user/([^/]+)" for method "GET"
|
|
* @expectedExceptionMessage Cannot register two routes matching "/user/([^/]+)" for method "GET"
|
|
*/
|
|
*/
|
|
- public function testDuplicateVariableRoute() {
|
|
|
|
- \FastRoute\simpleDispatcher(function(RouteCollector $r) {
|
|
|
|
|
|
+ public function testDuplicateVariableRoute()
|
|
|
|
+ {
|
|
|
|
+ \FastRoute\simpleDispatcher(function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{id}', 'handler0'); // oops, forgot \d+ restriction ;)
|
|
$r->addRoute('GET', '/user/{id}', 'handler0'); // oops, forgot \d+ restriction ;)
|
|
$r->addRoute('GET', '/user/{name}', 'handler1');
|
|
$r->addRoute('GET', '/user/{name}', 'handler1');
|
|
}, $this->generateDispatcherOptions());
|
|
}, $this->generateDispatcherOptions());
|
|
@@ -89,8 +96,9 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedExceptionMessage Cannot register two routes matching "/user" for method "GET"
|
|
* @expectedExceptionMessage Cannot register two routes matching "/user" for method "GET"
|
|
*/
|
|
*/
|
|
- public function testDuplicateStaticRoute() {
|
|
|
|
- \FastRoute\simpleDispatcher(function(RouteCollector $r) {
|
|
|
|
|
|
+ public function testDuplicateStaticRoute()
|
|
|
|
+ {
|
|
|
|
+ \FastRoute\simpleDispatcher(function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user', 'handler0');
|
|
$r->addRoute('GET', '/user', 'handler0');
|
|
$r->addRoute('GET', '/user', 'handler1');
|
|
$r->addRoute('GET', '/user', 'handler1');
|
|
}, $this->generateDispatcherOptions());
|
|
}, $this->generateDispatcherOptions());
|
|
@@ -100,8 +108,9 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedExceptionMessage Static route "/user/nikic" is shadowed by previously defined variable route "/user/([^/]+)" for method "GET"
|
|
* @expectedExceptionMessage Static route "/user/nikic" is shadowed by previously defined variable route "/user/([^/]+)" for method "GET"
|
|
*/
|
|
*/
|
|
- public function testShadowedStaticRoute() {
|
|
|
|
- \FastRoute\simpleDispatcher(function(RouteCollector $r) {
|
|
|
|
|
|
+ public function testShadowedStaticRoute()
|
|
|
|
+ {
|
|
|
|
+ \FastRoute\simpleDispatcher(function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/nikic', 'handler1');
|
|
$r->addRoute('GET', '/user/nikic', 'handler1');
|
|
}, $this->generateDispatcherOptions());
|
|
}, $this->generateDispatcherOptions());
|
|
@@ -111,18 +120,20 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedException \FastRoute\BadRouteException
|
|
* @expectedExceptionMessage Regex "(en|de)" for parameter "lang" contains a capturing group
|
|
* @expectedExceptionMessage Regex "(en|de)" for parameter "lang" contains a capturing group
|
|
*/
|
|
*/
|
|
- public function testCapturing() {
|
|
|
|
- \FastRoute\simpleDispatcher(function(RouteCollector $r) {
|
|
|
|
|
|
+ public function testCapturing()
|
|
|
|
+ {
|
|
|
|
+ \FastRoute\simpleDispatcher(function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/{lang:(en|de)}', 'handler0');
|
|
$r->addRoute('GET', '/{lang:(en|de)}', 'handler0');
|
|
}, $this->generateDispatcherOptions());
|
|
}, $this->generateDispatcherOptions());
|
|
}
|
|
}
|
|
|
|
|
|
- public function provideFoundDispatchCases() {
|
|
|
|
|
|
+ public function provideFoundDispatchCases()
|
|
|
|
+ {
|
|
$cases = [];
|
|
$cases = [];
|
|
|
|
|
|
// 0 -------------------------------------------------------------------------------------->
|
|
// 0 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
};
|
|
};
|
|
|
|
|
|
@@ -135,7 +146,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 1 -------------------------------------------------------------------------------------->
|
|
// 1 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/handler0', 'handler0');
|
|
$r->addRoute('GET', '/handler0', 'handler0');
|
|
$r->addRoute('GET', '/handler1', 'handler1');
|
|
$r->addRoute('GET', '/handler1', 'handler1');
|
|
$r->addRoute('GET', '/handler2', 'handler2');
|
|
$r->addRoute('GET', '/handler2', 'handler2');
|
|
@@ -150,7 +161,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 2 -------------------------------------------------------------------------------------->
|
|
// 2 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('GET', '/user/{name}', 'handler2');
|
|
$r->addRoute('GET', '/user/{name}', 'handler2');
|
|
@@ -198,11 +209,10 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 6 -------------------------------------------------------------------------------------->
|
|
// 6 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/12345/extension', 'handler1');
|
|
$r->addRoute('GET', '/user/12345/extension', 'handler1');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}.{extension}', 'handler2');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}.{extension}', 'handler2');
|
|
-
|
|
|
|
};
|
|
};
|
|
|
|
|
|
$method = 'GET';
|
|
$method = 'GET';
|
|
@@ -214,7 +224,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 7 ----- Test GET method fallback on HEAD route miss ------------------------------------>
|
|
// 7 ----- Test GET method fallback on HEAD route miss ------------------------------------>
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('GET', '/static0', 'handler2');
|
|
$r->addRoute('GET', '/static0', 'handler2');
|
|
@@ -264,7 +274,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 11 ---- More specified routes are not shadowed by less specific of another method ------>
|
|
// 11 ---- More specified routes are not shadowed by less specific of another method ------>
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('POST', '/user/{name:[a-z]+}', 'handler1');
|
|
$r->addRoute('POST', '/user/{name:[a-z]+}', 'handler1');
|
|
};
|
|
};
|
|
@@ -278,7 +288,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 12 ---- Handler of more specific routes is used, if it occurs first -------------------->
|
|
// 12 ---- Handler of more specific routes is used, if it occurs first -------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('POST', '/user/{name:[a-z]+}', 'handler1');
|
|
$r->addRoute('POST', '/user/{name:[a-z]+}', 'handler1');
|
|
$r->addRoute('POST', '/user/{name}', 'handler2');
|
|
$r->addRoute('POST', '/user/{name}', 'handler2');
|
|
@@ -293,7 +303,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 13 ---- Route with constant suffix ----------------------------------------------------->
|
|
// 13 ---- Route with constant suffix ----------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}/edit', 'handler1');
|
|
$r->addRoute('GET', '/user/{name}/edit', 'handler1');
|
|
};
|
|
};
|
|
@@ -307,7 +317,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 14 ---- Handle multiple methods with the same handler ---------------------------------->
|
|
// 14 ---- Handle multiple methods with the same handler ---------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute(['GET', 'POST'], '/user', 'handlerGetPost');
|
|
$r->addRoute(['GET', 'POST'], '/user', 'handlerGetPost');
|
|
$r->addRoute(['DELETE'], '/user', 'handlerDelete');
|
|
$r->addRoute(['DELETE'], '/user', 'handlerDelete');
|
|
$r->addRoute([], '/user', 'handlerNone');
|
|
$r->addRoute([], '/user', 'handlerNone');
|
|
@@ -318,53 +328,53 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
$cases[] = ['POST', '/user', $callback, 'handlerGetPost', $argDict];
|
|
$cases[] = ['POST', '/user', $callback, 'handlerGetPost', $argDict];
|
|
$cases[] = ['DELETE', '/user', $callback, 'handlerDelete', $argDict];
|
|
$cases[] = ['DELETE', '/user', $callback, 'handlerDelete', $argDict];
|
|
|
|
|
|
- // 15 ----
|
|
|
|
|
|
+ // 17 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('POST', '/user.json', 'handler0');
|
|
$r->addRoute('POST', '/user.json', 'handler0');
|
|
$r->addRoute('GET', '/{entity}.json', 'handler1');
|
|
$r->addRoute('GET', '/{entity}.json', 'handler1');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['GET', '/user.json', $callback, 'handler1', ['entity' => 'user']];
|
|
$cases[] = ['GET', '/user.json', $callback, 'handler1', ['entity' => 'user']];
|
|
|
|
|
|
- // 16 ----
|
|
|
|
|
|
+ // 18 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '', 'handler0');
|
|
$r->addRoute('GET', '', 'handler0');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['GET', '', $callback, 'handler0', []];
|
|
$cases[] = ['GET', '', $callback, 'handler0', []];
|
|
|
|
|
|
- // 17 ----
|
|
|
|
|
|
+ // 19 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('HEAD', '/a/{foo}', 'handler0');
|
|
$r->addRoute('HEAD', '/a/{foo}', 'handler0');
|
|
$r->addRoute('GET', '/b/{foo}', 'handler1');
|
|
$r->addRoute('GET', '/b/{foo}', 'handler1');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['HEAD', '/b/bar', $callback, 'handler1', ['foo' => 'bar']];
|
|
$cases[] = ['HEAD', '/b/bar', $callback, 'handler1', ['foo' => 'bar']];
|
|
|
|
|
|
- // 18 ----
|
|
|
|
|
|
+ // 20 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('HEAD', '/a', 'handler0');
|
|
$r->addRoute('HEAD', '/a', 'handler0');
|
|
$r->addRoute('GET', '/b', 'handler1');
|
|
$r->addRoute('GET', '/b', 'handler1');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['HEAD', '/b', $callback, 'handler1', []];
|
|
$cases[] = ['HEAD', '/b', $callback, 'handler1', []];
|
|
|
|
|
|
- // 19 ----
|
|
|
|
|
|
+ // 21 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/foo', 'handler0');
|
|
$r->addRoute('GET', '/foo', 'handler0');
|
|
$r->addRoute('HEAD', '/{bar}', 'handler1');
|
|
$r->addRoute('HEAD', '/{bar}', 'handler1');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['HEAD', '/foo', $callback, 'handler1', ['bar' => 'foo']];
|
|
$cases[] = ['HEAD', '/foo', $callback, 'handler1', ['bar' => 'foo']];
|
|
|
|
|
|
- // 20 ----
|
|
|
|
|
|
+ // 22 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('*', '/user', 'handler0');
|
|
$r->addRoute('*', '/user', 'handler0');
|
|
$r->addRoute('*', '/{user}', 'handler1');
|
|
$r->addRoute('*', '/{user}', 'handler1');
|
|
$r->addRoute('GET', '/user', 'handler2');
|
|
$r->addRoute('GET', '/user', 'handler2');
|
|
@@ -372,39 +382,49 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
$cases[] = ['GET', '/user', $callback, 'handler2', []];
|
|
$cases[] = ['GET', '/user', $callback, 'handler2', []];
|
|
|
|
|
|
- // 21 ----
|
|
|
|
|
|
+ // 23 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('*', '/user', 'handler0');
|
|
$r->addRoute('*', '/user', 'handler0');
|
|
$r->addRoute('GET', '/user', 'handler1');
|
|
$r->addRoute('GET', '/user', 'handler1');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['POST', '/user', $callback, 'handler0', []];
|
|
$cases[] = ['POST', '/user', $callback, 'handler0', []];
|
|
|
|
|
|
- // 22 ----
|
|
|
|
|
|
+ // 24 ----
|
|
|
|
|
|
$cases[] = ['HEAD', '/user', $callback, 'handler1', []];
|
|
$cases[] = ['HEAD', '/user', $callback, 'handler1', []];
|
|
|
|
|
|
- // 23 ----
|
|
|
|
|
|
+ // 25 ----
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/{bar}', 'handler0');
|
|
$r->addRoute('GET', '/{bar}', 'handler0');
|
|
$r->addRoute('*', '/foo', 'handler1');
|
|
$r->addRoute('*', '/foo', 'handler1');
|
|
};
|
|
};
|
|
|
|
|
|
$cases[] = ['GET', '/foo', $callback, 'handler0', ['bar' => 'foo']];
|
|
$cases[] = ['GET', '/foo', $callback, 'handler0', ['bar' => 'foo']];
|
|
|
|
|
|
|
|
+ // 26 ----
|
|
|
|
+
|
|
|
|
+ $callback = function(RouteCollector $r) {
|
|
|
|
+ $r->addRoute('GET', '/user', 'handler0');
|
|
|
|
+ $r->addRoute('*', '/{foo:.*}', 'handler1');
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ $cases[] = ['POST', '/bar', $callback, 'handler1', ['foo' => 'bar']];
|
|
|
|
+
|
|
// x -------------------------------------------------------------------------------------->
|
|
// x -------------------------------------------------------------------------------------->
|
|
|
|
|
|
return $cases;
|
|
return $cases;
|
|
}
|
|
}
|
|
|
|
|
|
- public function provideNotFoundDispatchCases() {
|
|
|
|
|
|
+ public function provideNotFoundDispatchCases()
|
|
|
|
+ {
|
|
$cases = [];
|
|
$cases = [];
|
|
|
|
|
|
// 0 -------------------------------------------------------------------------------------->
|
|
// 0 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
};
|
|
};
|
|
|
|
|
|
@@ -431,7 +451,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 3 -------------------------------------------------------------------------------------->
|
|
// 3 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/handler0', 'handler0');
|
|
$r->addRoute('GET', '/handler0', 'handler0');
|
|
$r->addRoute('GET', '/handler1', 'handler1');
|
|
$r->addRoute('GET', '/handler1', 'handler1');
|
|
$r->addRoute('GET', '/handler2', 'handler2');
|
|
$r->addRoute('GET', '/handler2', 'handler2');
|
|
@@ -444,7 +464,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 4 -------------------------------------------------------------------------------------->
|
|
// 4 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('GET', '/user/{name}', 'handler2');
|
|
$r->addRoute('GET', '/user/{name}', 'handler2');
|
|
@@ -468,19 +488,20 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
// reuse callback from #5
|
|
// reuse callback from #5
|
|
$method = 'HEAD';
|
|
$method = 'HEAD';
|
|
|
|
|
|
- $cases[] = array($method, $uri, $callback);
|
|
|
|
|
|
+ $cases[] = [$method, $uri, $callback];
|
|
|
|
|
|
// x -------------------------------------------------------------------------------------->
|
|
// x -------------------------------------------------------------------------------------->
|
|
|
|
|
|
return $cases;
|
|
return $cases;
|
|
}
|
|
}
|
|
|
|
|
|
- public function provideMethodNotAllowedDispatchCases() {
|
|
|
|
|
|
+ public function provideMethodNotAllowedDispatchCases()
|
|
|
|
+ {
|
|
$cases = [];
|
|
$cases = [];
|
|
|
|
|
|
// 0 -------------------------------------------------------------------------------------->
|
|
// 0 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
};
|
|
};
|
|
|
|
|
|
@@ -492,7 +513,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 1 -------------------------------------------------------------------------------------->
|
|
// 1 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
$r->addRoute('GET', '/resource/123/456', 'handler0');
|
|
$r->addRoute('POST', '/resource/123/456', 'handler1');
|
|
$r->addRoute('POST', '/resource/123/456', 'handler1');
|
|
$r->addRoute('PUT', '/resource/123/456', 'handler2');
|
|
$r->addRoute('PUT', '/resource/123/456', 'handler2');
|
|
@@ -507,7 +528,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 2 -------------------------------------------------------------------------------------->
|
|
// 2 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
|
|
$r->addRoute('POST', '/user/{name}/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('POST', '/user/{name}/{id:[0-9]+}', 'handler1');
|
|
$r->addRoute('PUT', '/user/{name}/{id:[0-9]+}', 'handler2');
|
|
$r->addRoute('PUT', '/user/{name}/{id:[0-9]+}', 'handler2');
|
|
@@ -522,7 +543,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 3 -------------------------------------------------------------------------------------->
|
|
// 3 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('POST', '/user/{name}', 'handler1');
|
|
$r->addRoute('POST', '/user/{name}', 'handler1');
|
|
$r->addRoute('PUT', '/user/{name:[a-z]+}', 'handler2');
|
|
$r->addRoute('PUT', '/user/{name:[a-z]+}', 'handler2');
|
|
$r->addRoute('PATCH', '/user/{name:[a-z]+}', 'handler3');
|
|
$r->addRoute('PATCH', '/user/{name:[a-z]+}', 'handler3');
|
|
@@ -536,7 +557,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 4 -------------------------------------------------------------------------------------->
|
|
// 4 -------------------------------------------------------------------------------------->
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute(['GET', 'POST'], '/user', 'handlerGetPost');
|
|
$r->addRoute(['GET', 'POST'], '/user', 'handlerGetPost');
|
|
$r->addRoute(['DELETE'], '/user', 'handlerDelete');
|
|
$r->addRoute(['DELETE'], '/user', 'handlerDelete');
|
|
$r->addRoute([], '/user', 'handlerNone');
|
|
$r->addRoute([], '/user', 'handlerNone');
|
|
@@ -546,7 +567,7 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
// 5
|
|
// 5
|
|
|
|
|
|
- $callback = function(RouteCollector $r) {
|
|
|
|
|
|
+ $callback = function (RouteCollector $r) {
|
|
$r->addRoute('POST', '/user.json', 'handler0');
|
|
$r->addRoute('POST', '/user.json', 'handler0');
|
|
$r->addRoute('GET', '/{entity}.json', 'handler1');
|
|
$r->addRoute('GET', '/{entity}.json', 'handler1');
|
|
};
|
|
};
|
|
@@ -557,5 +578,4 @@ abstract class DispatcherTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
return $cases;
|
|
return $cases;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|