Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests on route:list sort command #51202

Merged
Changes from all 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
27 changes: 26 additions & 1 deletion tests/Foundation/Console/RouteListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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]);
Expand Down Expand Up @@ -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"]}]';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this test too, because I added a third route (with a domain) in the setUp method.


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