Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ protected function getRouteInformation(Route $route)
*/
protected function sortRoutes($sort, array $routes)
{
if ($sort === 'definition') {
return $routes;
}

if (Str::contains($sort, ',')) {
$sort = explode(',', $sort);
}
Expand Down Expand Up @@ -495,7 +499,7 @@ protected function getOptions()
['path', null, InputOption::VALUE_OPTIONAL, 'Only show routes matching the given path pattern'],
['except-path', null, InputOption::VALUE_OPTIONAL, 'Do not display the routes matching the given path pattern'],
['reverse', 'r', InputOption::VALUE_NONE, 'Reverse the ordering of the routes'],
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, method, uri, name, action, middleware) to sort by', 'uri'],
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, method, uri, name, action, middleware, definition) to sort by', 'uri'],
['except-vendor', null, InputOption::VALUE_NONE, 'Do not display routes defined by vendor packages'],
['only-vendor', null, InputOption::VALUE_NONE, 'Only display routes defined by vendor packages'],
];
Expand Down
20 changes: 20 additions & 0 deletions tests/Foundation/Console/RouteListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ public function testSortRouteListDesc()
$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
}

public function testSortRouteListDefault()
{
$this->app->call('route:list', ['--json' => true]);
$output = $this->app->output();

$expectedOrder = '[{"domain":null,"method":"GET|HEAD","uri":"example","name":null,"action":"Closure","middleware":["exampleMiddleware"]},{"domain":null,"method":"GET|HEAD","uri":"example-group","name":null,"action":"Closure","middleware":["web","auth"]}, {"domain":"sub","method":"GET|HEAD","uri":"sub-example","name":null,"action":"Closure","middleware":["exampleMiddleware"]}]';

$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
}

public function testSortRouteListPrecedence()
{
$this->app->call('route:list', ['--json' => true, '--sort' => 'precedence']);
$output = $this->app->output();

$expectedOrder = '[{"domain":null,"method":"GET|HEAD","uri":"example","name":null,"action":"Closure","middleware":["exampleMiddleware"]},{"domain":"sub","method":"GET|HEAD","uri":"sub-example","name":null,"action":"Closure","middleware":["exampleMiddleware"]}, {"domain":null,"method":"GET|HEAD","uri":"example-group","name":null,"action":"Closure","middleware":["web","auth"]}]';

$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
}

public function testMiddlewareGroupsAssignmentInCli()
{
$this->app->call('route:list', ['-v' => true]);
Expand Down