Skip to content

Commit 49029ae

Browse files
committed
Added caution alert when sorting criterion != priority
1 parent ced94da commit 49029ae

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8585
$container = $this->fileLinkFormatter ? \Closure::fromCallable([$this, 'getContainerBuilder']) : null;
8686
$sortOption = $input->getOption('sort');
8787
$routes = $this->sortRoutes($this->router->getRouteCollection(), $sortOption);
88+
if ('priority' !== $sortOption) {
89+
$io->caution('The routes list is not sorted in the parsing order.');
90+
}
8891

8992
if ($name) {
9093
if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {

src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testSortingByPriority()
2121
$result = $tester->execute(['--sort' => 'priority'], ['decorated' => false]);
2222
$this->assertSame(0, $result, 'Returns 0 in case of success');
2323
$this->assertRegExp('/(charlie).*\n\W*(alfa).*\n\W*(delta).*\n\W*(bravo)/m', $tester->getDisplay(true));
24+
$this->assertStringNotContainsString('! [CAUTION] The routes list is not sorted in the parsing order.', $tester->getDisplay(true));
2425
}
2526

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

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

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

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

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

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

8895
private function createCommandTester(): CommandTester

0 commit comments

Comments
 (0)