From c2668c7deeabb59c96181b8a6e2bb2c08b9425eb Mon Sep 17 00:00:00 2001 From: Francescu GAROBY Date: Wed, 24 Apr 2024 23:02:25 +0200 Subject: [PATCH] Add some tests (#51202) --- .../Console/RouteListCommandTest.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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); }