8000 bug #45947 [FrameworkBundle] [Command] Fix `debug:router --no-interac… · symfony/symfony@0a0345a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a0345a

Browse files
committed
bug #45947 [FrameworkBundle] [Command] Fix debug:router --no-interaction error … (WilliamBoulle)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] [Command] Fix `debug:router --no-interaction` error … | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #45777 | License | MIT When command `debug:router` is used in non-interactive mode with a name that matches more than one route, render the list of matching routes ![debug_router_profiler_nointeraction](https://user-images.githubusercontent.com/18715733/161756561-cb2b5f75-111d-4920-8e81-8066b302a887.png) Commits ------- e92e261 [FrameworkBundle] [Command] Fix `debug:router --no-interaction` error …
2 parents 33420de + e92e261 commit 0a0345a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181
$routes = $this->router->getRouteCollection();
8282

8383
if ($name) {
84-
if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {
84+
$route = $routes->get($name);
85+
$matchingRoutes = $this->findRouteNameContaining($name, $routes);
86+
87+
if (!$input->isInteractive() && !$route && \count($matchingRoutes) > 1) {
88+
$helper->describe($io, $this->findRouteContaining($name, $routes), [
89+
'format' => $input->getOption('format'),
90+
'raw_text' => $input->getOption('raw'),
91+
'show_controllers' => $input->getOption('show-controllers'),
92+
'output' => $io,
93+
]);
94+
95+
return 0;
96+
}
97+
98+
if (!$route && $matchingRoutes) {
8599
$default = 1 === \count($matchingRoutes) ? $matchingRoutes[0] : null;
86100
$name = $io->choice('Select one of the matching routes', $matchingRoutes, $default);
87101
$route = $routes->get($name);
@@ -120,4 +134,16 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
120134

121135
return $foundRoutesNames;
122136
}
137+
138+
private function findRouteContaining(string $name, RouteCollection $routes): RouteCollection
139+
{
140+
$foundRoutes = new RouteCollection();
141+
foreach ($routes as $routeName => $route) {
142+
if (false !== stripos($routeName, $name)) {
143+
$foundRoutes->add($routeName, $route);
144+
}
145+
}
146+
147+
return $foundRoutes;
148+
}
123149
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ public function testSearchMultipleRoutes()
6161
$this->assertStringContainsString('/test', $tester->getDisplay());
6262
}
6363

64+
public function testSearchMultipleRoutesWithoutInteraction()
65+
{
66+
$tester = $this->createCommandTester();
67+
$ret = $tester->execute(['name' => 'routerdebug'], ['interactive' => false]);
68+
69+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
70+
$this->assertStringNotContainsString('Select one of the matching routes:', $tester->getDisplay());
71+
$this->assertStringContainsString('routerdebug_session_welcome', $tester->getDisplay());
72+
$this->assertStringContainsString('/session', $tester->getDisplay());
73+
$this->assertStringContainsString('routerdebug_session_welcome_name', $tester->getDisplay());
74+
$this->assertStringContainsString('/session/{name} ', $tester->getDisplay());
75+
$this->assertStringContainsString('routerdebug_session_logout', $tester->getDisplay());
76+
$this->assertStringContainsString('/session_logout', $tester->getDisplay());
77+
$this->assertStringContainsString('routerdebug_test', $tester->getDisplay());
78+
$this->assertStringContainsString('/test', $tester->getDisplay());
79+
}
80+
6481
public function testSearchWithThrow()
6582
{
6683
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)
0