8000 PR 36579 corrections via @nicolas-grekas · symfony/symfony@ced94da · GitHub
[go: up one dir, main page]

Skip to content

Commit ced94da

Browse files
committed
PR 36579 corrections via @nicolas-grekas
1 parent afba921 commit ced94da

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8282
$io = new SymfonyStyle($input, $output);
8383
$name = $input->getArgument('name');
8484
$helper = new DescriptorHelper($this->fileLinkFormatter);
85-
$routes = $this->router->getRouteCollection();
8685
$container = $this->fileLinkFormatter ? \Closure::fromCallable([$this, 'getContainerBuilder']) : null;
8786
$sortOption = $input->getOption('sort');
88-
89-
if (null !== $sortOption) {
90-
$routes = $this->sortRoutes($routes, $sortOption);
91-
}
87+
$routes = $this->sortRoutes($this->router->getRouteCollection(), $sortOption);
9288

9389
if ($name) {
9490
if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {
@@ -135,18 +131,12 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
135131

136132
private function sortRoutes(RouteCollection $routes, string $propertyName): RouteCollection
137133
{
138-
$validOptions = ['', 'priority', 'name', 'path'];
139134
$sortedRoutes = $routes->all();
140135
if ('name' === $propertyName) {
141136
ksort($sortedRoutes);
142137
} elseif ('path' === $propertyName) {
143-
uasort(
144-
$sortedRoutes,
145-
static function (Route $a, Route $b): int {
146-
return $a->getPath() <=> $b->getPath();
147-
}
148-
);
149-
} elseif (!\in_array($propertyName, $validOptions)) {
138+
uasort($sortedRoutes, function ($a, $b) { return $a->getPath() <=> $b->getPath(); });
139+
} elseif ('priority' !== $propertyName) {
150140
throw new InvalidArgumentException(sprintf('The option "%s" is not valid.', $propertyName));
151141
}
152142
$routeCollection = new RouteCollection();

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public function testSortingByPriority()
1919
{
2020
$tester = $this->createCommandTester();
2121
$result = $tester->execute(['--sort' => 'priority'], ['decorated' => false]);
22-
$this->assertEquals(0, $result, 'Returns 0 in case of success');
22+
$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));
2424
}
2525

2626
public function testSortingByName()
2727
{
2828
$tester = $this->createCommandTester();
2929
$result = $tester->execute(['--sort' => 'name'], ['decorated' => false]);
30-
$this->assertEquals(0, $result, 'Returns 0 in case of success');
30+
$this->assertSame(0, $result, 'Returns 0 in case of success');
3131
$this->assertRegExp('/(alfa).*\n\W*(bravo).*\n\W*(charlie).*\n\W*(delta)/m', $tester->getDisplay(true));
3232
}
3333

3434
public function testSortingByPath()
3535
{
3636
$tester = $this->createCommandTester();
3737
$result = $tester->execute(['--sort' => 'path'], ['decorated' => false]);
38-
$this->assertEquals(0, $result, 'Returns 0 in case of success');
38+
$this->assertSame(0, $result, 'Returns 0 in case of success');
3939
$this->assertRegExp('/(\/romeo).*\n.*(\/sierra).*\n.*(\/tango).*\n.*(\/uniform)/m', $tester->getDisplay(true));
4040
}
4141

@@ -57,26 +57,34 @@ public function testSortingByPriorityWithDuplicatePath()
5757
{
5858
$tester = $this->createCommandTesterWithDuplicatePath();
5959
$result = $tester->execute(['--sort' => 'priority'], ['decorated' => false]);
60-
$this->assertEquals(0, $result, 'Returns 0 in case of success');
60+
$this->assertSame(0, $result, 'Returns 0 in case of success');
6161
$this->assertRegExp('/(charlie).*\n\W*(alfa).*\n\W*(delta).*\n\W*(bravo).*\n\W*(echo)/m', $tester->getDisplay(true));
6262
}
6363

6464
public function testSortingByNameWithDuplicatePath()
6565
{
6666
$tester = $this->createCommandTesterWithDuplicatePath();
6767
$result = $tester->execute(['--sort' => 'name'], ['decorated' => false]);
68-
$this->assertEquals(0, $result, 'Returns 0 in case of success');
68+
$this->assertSame(0, $result, 'Returns 0 in case of success');
6969
$this->assertRegExp('/(alfa).*\n\W*(bravo).*\n\W*(charlie).*\n\W*(delta).*\n\W*(echo)/m', $tester->getDisplay(true));
7070
}
7171

7272
public function testSortingByPathWithDuplicatePath()
7373
{
7474
$tester = $this->createCommandTesterWithDuplicatePath();
7575
$result = $tester->execute(['--sort' => 'path'], ['decorated' => false]);
76-
$this->assertEquals(0, $result, 'Returns 0 in case of success');
76+
$this->assertSame(0, $result, 'Returns 0 in case of success');
7777
$this->assertRegExp('/(\/romeo).*\n.*(\/sierra).*\n.*(\/tango).*\n.*(\/uniform).*\n.*(\/uniform)/m', $tester->getDisplay(true));
7878
}
7979

80+
public function testWithoutCallingSortOptionExplicitly()
81+
{
82+
$tester = $this->createCommandTester();
83+
$result = $tester->execute([], ['decorated' => false]);
84+
$this->assertSame(0, $result, 'Returns 0 in case of success');
85+
$this->assertRegExp('/(charlie).*\n\W*(alfa).*\n\W*(delta).*\n\W*(bravo)/m', $tester->getDisplay(true));
86+
}
87+
8088
private function createCommandTester(): CommandTester
8189
{
8290
$application = new Application($this->getKernel());

0 commit comments

Comments
 (0)
0