Skip to content
Permalink
Browse files

Add basic tests for Router::scope().

  • Loading branch information...
markstory committed Jun 24, 2014
1 parent 67d9b42 commit f0af8f8fe0ad33cca400f1f433b619404a7a45f3
Showing with 31 additions and 1 deletion.
  1. +2 −1 src/Routing/Router.php
  2. +29 −0 tests/TestCase/Routing/RouterTest.php
@@ -1076,6 +1076,7 @@ public static function parseNamedParams(Request $request, $options = []) {
* @param array $params An array of routing defaults to add to each connected route.
* If you have no parameters, this argument can be a callable.
* @param callable $callback The callback to invoke with the scoped collection.
* @throws \InvalidArgumentException When an invalid callable is provided.
* @return void
*/
public static function scope($path, $params = [], $callback = null) {
@@ -1085,7 +1086,7 @@ public static function scope($path, $params = [], $callback = null) {
}
if (!is_callable($callback)) {
$msg = 'Need a callable function/object to connect routes.';
throw Error\Exception($msg);
throw new \InvalidArgumentException($msg);
}
$collection = new ScopedRouteCollection($path, $params, static::$_validExtensions);
@@ -2856,4 +2856,33 @@ public function testPromote() {
$this->assertEquals('/en/posts/index', $result, 'promote() should move 2nd route ahead.');
}
/**
* Test the scope() method
*
* @return void
*/
public function testScope() {
Router::scope('/path', ['param' => 'value'], function($routes) {
$this->assertInstanceOf('Cake\Routing\ScopedRouteCollection', $routes);
$this->assertCount(0, $routes->routes());
$this->assertEquals('/path', $routes->path());
$this->assertEquals(['param' => 'value'], $routes->params());
$routes->connect('/articles', ['controller' => 'Articles']);
});
Router::scope('/path', function($routes) {
$this->assertCount(0, $routes->routes());
});
}
/**
* Test the scope() method
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testScopeError() {
Router::scope('/path', 'derpy');
}
}

0 comments on commit f0af8f8

Please sign in to comment.
You can’t perform that action at this time.