8000 [11.x] Allow sorting routes by precedence in artisan routes:list. (#5… · tibbsa/laravel-framework@9a9cb2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a9cb2f

Browse files
[11.x] Allow sorting routes by precedence in artisan routes:list. (laravel#53706)
* Allow sorting route by precedence. * Fix style. * rename option * fix test --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent bbd61dd commit 9a9cb2f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Illuminate/Foundation/Console/RouteListCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ protected function getRouteInformation(Route $route)
157157
*/
158158
protected function sortRoutes($sort, array $routes)
159159
{
160+
if ($sort === 'definition') {
161+
return $routes;
162+
}
163+
160164
if (Str::contains($sort, ',')) {
161165
$sort = explode(',', $sort);
162166
}
@@ -495,7 +499,7 @@ protected function getOptions()
495499
['path', null, InputOption::VALUE_OPTIONAL, 'Only show routes matching the given path pattern'],
496500
['except-path', null, InputOption::VALUE_OPTIONAL, 'Do not display the routes matching the given path pattern'],
497501
['reverse', 'r', InputOption::VALUE_NONE, 'Reverse the ordering of the routes'],
498-
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, method, uri, name, action, middleware) to sort by', 'uri'],
502+
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, method, uri, name, action, middleware, definition) to sort by', 'uri'],
499503
['except-vendor', null, InputOption::VALUE_NONE, 'Do not display routes defined by vendor packages'],
500504
['only-vendor', null, InputOption::VALUE_NONE, 'Only display routes defined by vendor packages'],
501505
];

tests/Foundation/Console/RouteListCommandTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ public function testSortRouteListDesc()
9797
$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
9898
}
9999

100+
public function testSortRouteListDefault()
101+
{
102+
$this->app->call('route:list', ['--json' => true]);
103+
$output = $this->app->output();
104+
105+
$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"]}]';
106+
107+
$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
108+
}
109+
110+
public function testSortRouteListPrecedence()
111+
{
112+
$this->app->call('route:list', ['--json' => true, '--sort' => 'definition']);
113+
$output = $this->app->output();
114+
115+
$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"]}]';
116+
117+
$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
118+
}
119+
100120
public function testMiddlewareGroupsAssignmentInCli()
101121
{
102122
$this->app->call('route:list', ['-v' => true]);

0 commit comments

Comments
 (0)
0