Skip to content

Commit

Permalink
Add some tests (#51202)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaroby authored Apr 24, 2024
1 parent f8300e3 commit c2668c7
Showing 1 changed file with 26 additions and 1 deletion.
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"]}]';

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

0 comments on commit c2668c7

Please sign in to comment.