Skip to content

Commit c014247

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: [FrameworkBundle] [Command] Fix `debug:router --no-interaction` error … [Intl] Update the ICU data to 71.1 - 4.4 Add tests to messenger connection get for OraclePlatform [Process] Fix Process::getEnv() when setEnv() hasn't been called before [ExpressionLanguage] Fix matching null against a regular expression
2 parents 202c423 + f75c21d commit c014247

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Command/RouterDebugCommand.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9292
}
9393

9494
if ($name) {
95-
if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {
95+
$route = $routes->get($name);
96+
$matchingRoutes = $this->findRouteNameContaining($name, $routes);
97+
98+
if (!$input->isInteractive() && !$route && \count($matchingRoutes) > 1) {
99+
$helper->describe($io, $this->findRouteContaining($name, $routes), [
100+
'format' => $input->getOption('format'),
101+
'raw_text' => $input->getOption('raw'),
102+
'show_controllers' => $input->getOption('show-controllers'),
103+
'output' => $io,
104+
]);
105+
106+
return 0;
107+
}
108+
109+
if (!$route && $matchingRoutes) {
96110
$default = 1 === \count($matchingRoutes) ? $matchingRoutes[0] : null;
97111
$name = $io->choice('Select one of the matching routes', $matchingRoutes, $default);
98112
$route = $routes->get($name);
@@ -147,4 +161,16 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
147161
$suggestions->suggestValues($helper->getFormats());
148162
}
149163
}
164+
165+
private function findRouteContaining(string $name, RouteCollection $routes): RouteCollection
166+
{
167+
$foundRoutes = new RouteCollection();
168+
foreach ($routes as $routeName => $route) {
169+
if (false !== stripos($routeName, $name)) {
170+
$foundRoutes->add($routeName, $route);
171+
}
172+
}
173+
174+
return $foundRoutes;
175+
}
150176
}

Tests/Functional/RouterDebugCommandTest.php

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

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

0 commit comments

Comments
 (0)