diff --git a/tests/Foundation/Console/RouteListCommandTest.php b/tests/Foundation/Console/RouteListCommandTest.php index 2b9b72c0f981..b032b36acf64 100644 --- a/tests/Foundation/Console/RouteListCommandTest.php +++ b/tests/Foundation/Console/RouteListCommandTest.php @@ -56,6 +56,11 @@ protected function setUp(): void return 'Hello World'; })->middleware('exampleMiddleware'); + $router->get('/sub-example', function () { + return 'Hello World'; + })->domain('sub') + ->middleware('exampleMiddleware'); + $router->get('/example-group', function () { return 'Hello Group'; })->middleware(['web', 'auth']); @@ -74,6 +79,26 @@ public function testNoMiddlewareIfNotVerbose() $this->assertStringNotContainsString('exampleMiddleware', $output); } + public function testSortRouteListAsc() + { + $this->app->call('route:list', ['--json' => true, '--sort' => 'domain,uri']); + $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 testSortRouteListDesc() + { + $this->app->call('route:list', ['--json' => true, '--sort' => 'domain,uri', '--reverse' => true]); + $output = $this->app->output(); + + $expectedOrder = '[{"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"]},{"domain":null,"method":"GET|HEAD","uri":"example","name":null,"action":"Closure","middleware":["exampleMiddleware"]}]'; + + $this->assertJsonStringEqualsJsonString($expectedOrder, $output); + } + public function testMiddlewareGroupsAssignmentInCli() { $this->app->call('route:list', ['-v' => true]); @@ -143,7 +168,7 @@ public function testMiddlewareGroupsExpandCorrectlySortedIfVeryVerbose() $this->app->call('route:list', ['--json' => true, '-vv' => 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":["Middleware 5","Middleware 1","Middleware 4","Middleware 2","Middleware 3"]}]'; + $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":["Middleware 5","Middleware 1","Middleware 4","Middleware 2","Middleware 3"]},{"domain":"sub","method":"GET|HEAD","uri":"sub-example","name":null,"action":"Closure","middleware":["exampleMiddleware"]}]'; $this->assertJsonStringEqualsJsonString($expectedOrder, $output); }