8000 [FrameworkBundle] [Routing] Added --sort to debug:router by vjandrea · Pull Request #36579 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] [Routing] Added --sort to debug:router #36579

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added caution alert when sorting criterion != priority
  • Loading branch information
vjandrea committed Jul 11, 2020
commit 49029ae2dc53dff1a74c8da425737f89184abe12
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$container = $this->fileLinkFormatter ? \Closure::fromCallable([$this, 'getContainerBuilder']) : null;
$sortOption = $input->getOption('sort');
$routes = $this->sortRoutes($this->router->getRouteCollection(), $sortOption);
if ('priority' !== $sortOption) {
$io->caution('The routes list is not sorted in the parsing order.');
}

if ($name) {
if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testSortingByPriority()
$result = $tester->execute(['--sort' => 'priority'], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(charlie).*\n\W*(alfa).*\n\W*(delta).*\n\W*(bravo)/m', $tester->getDisplay(true));
$this->assertStringNotContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

public function testSortingByName()
Expand All @@ -29,6 +30,7 @@ public function testSortingByName()
$result = $tester->execute(['--sort' => 'name'], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(alfa).*\n\W*(bravo).*\n\W*(charlie).*\n\W*(delta)/m', $tester->getDisplay(true));
$this->assertStringContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

public function testSortingByPath()
Expand All @@ -37,6 +39,7 @@ public function testSortingByPath()
$result = $tester->execute(['--sort' => 'path'], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(\/romeo).*\n.*(\/sierra).*\n.*(\/tango).*\n.*(\/uniform)/m', $tester->getDisplay(true));
$this->assertStringContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

public function testThrowsExceptionWithInvalidParameter()
Expand All @@ -59,6 +62,7 @@ public function testSortingByPriorityWithDuplicatePath()
$result = $tester->execute(['--sort' => 'priority'], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(charlie).*\n\W*(alfa).*\n\W*(delta).*\n\W*(bravo).*\n\W*(echo)/m', $tester->getDisplay(true));
$this->assertStringNotContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

public function testSortingByNameWithDuplicatePath()
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this test is useless as it doesn't cover anything new

Expand All @@ -67,6 +71,7 @@ public function testSortingByNameWithDuplicatePath()
$result = $tester->execute(['--sort' => 'name'], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(alfa).*\n\W*(bravo).*\n\W*(charlie).*\n\W*(delta).*\n\W*(echo)/m', $tester->getDisplay(true));
$this->assertStringContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

public function testSortingByPathWithDuplicatePath()
Copy link
Contributor

Choose a reason for hiding this comment

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

this test should actually also make sure the routes with the same path stay in the correct order as before (check routes names) as I mention in the stable sorting comment

Expand All @@ -75,6 +80,7 @@ public function testSortingByPathWithDuplicatePath()
$result = $tester->execute(['--sort' => 'path'], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(\/romeo).*\n.*(\/sierra).*\n.*(\/tango).*\n.*(\/uniform).*\n.*(\/uniform)/m', $tester->getDisplay(true));
$this->assertStringContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

public function testWithoutCallingSortOptionExplicitly()
Expand All @@ -83,6 +89,7 @@ public function testWithoutCallingSortOptionExplicitly()
$result = $tester->execute([], ['decorated' => false]);
$this->assertSame(0, $result, 'Returns 0 in case of success');
$this->assertRegExp('/(charlie).*\n\W*(alfa).*\n\W*(delta).*\n\W*(bravo)/m', $tester->getDisplay(true));
$this->assertStringNotContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
}

private function createCommandTester(): CommandTester
Expand Down
0