Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add the route name to the check subcommand
  • Loading branch information
antograssiot committed Aug 12, 2015
1 parent 1cf4fb7 commit 569dfd2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Shell/RoutesShell.php
Expand Up @@ -54,9 +54,15 @@ public function check($url)
{
try {
$route = Router::parse($url);
foreach (Router::routes() as $r) {
if ($r->match($route)) {
$name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
break;
}
}
$output = [
['Route name', 'URI template', 'Defaults'],
['', $url, json_encode($route)]
[$name, $url, json_encode($route)]
];
$this->helper('table')->output($output);
} catch (MissingRouteException $e) {
Expand Down
24 changes: 23 additions & 1 deletion tests/TestCase/Shell/RoutesShellTest.php
Expand Up @@ -105,7 +105,7 @@ public function testCheck()
$this->logicalAnd(
$this->contains(['Route name', 'URI template', 'Defaults']),
$this->contains([
'',
'articles:_action',
'/articles/index',
'{"action":"index","pass":[],"controller":"Articles","plugin":null}'
])
Expand All @@ -114,6 +114,28 @@ public function testCheck()
$this->shell->check('/articles/index');
}

/**
* Test checking an existing route with named route.
*
* @return void
*/
public function testCheckWithNamedRoute()
{
$this->table->expects($this->once())
->method('output')
->with(
$this->logicalAnd(
$this->contains(['Route name', 'URI template', 'Defaults']),
$this->contains([
'testName',
'/tests/index',
'{"action":"index","pass":[],"controller":"Tests","plugin":null}'
])
)
);
$this->shell->check('/tests/index');
}

/**
* Test checking an non-existing route.
*
Expand Down

0 comments on commit 569dfd2

Please sign in to comment.