|
12 | 12 | namespace Symfony\Bundle\FrameworkBundle\Tests\Console;
|
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Console\Application;
|
| 15 | +use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber; |
15 | 16 | use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
16 | 17 | use Symfony\Component\Console\Command\Command;
|
| 18 | +use Symfony\Component\Console\Event\ConsoleErrorEvent; |
| 19 | +use Symfony\Component\Console\Exception\CommandNotFoundException; |
17 | 20 | use Symfony\Component\Console\Input\ArrayInput;
|
18 | 21 | use Symfony\Component\Console\Input\InputInterface;
|
19 | 22 | use Symfony\Component\Console\Output\NullOutput;
|
@@ -226,6 +229,34 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
|
226 | 229 | $this->assertContains(trim('[WARNING] Some commands could not be registered:'), trim($display[1]));
|
227 | 230 | }
|
228 | 231 |
|
| 232 | + public function testSuggestingPackagesWithExactMatch() |
| 233 | + { |
| 234 | + $result = $this->createEventForSuggestingPackages('server:dump', []); |
| 235 | + $this->assertRegExp('/You may be looking for a command provided by the/', $result); |
| 236 | + } |
| 237 | + |
| 238 | + public function testSuggestingPackagesWithPartialMatchAndNoAlternatives() |
| 239 | + { |
| 240 | + $result = $this->createEventForSuggestingPackages('server', []); |
| 241 | + $this->assertRegExp('/You may be looking for a command provided by the/', $result); |
| 242 | + } |
| 243 | + |
| 244 | + public function testSuggestingPackagesWithPartialMatchAndAlternatives() |
| 245 | + { |
| 246 | + $result = $this->createEventForSuggestingPackages('server', ['server:run']); |
| 247 | + $this->assertNotRegExp('/You may be looking for a command provided by the/', $result); |
| 248 | + } |
| 249 | + |
| 250 | + private function createEventForSuggestingPackages(string $command, array $alternatives = []): string |
| 251 | + { |
| 252 | + $error = new CommandNotFoundException('', $alternatives); |
| 253 | + $event = new ConsoleErrorEvent(new ArrayInput([$command]), new NullOutput(), $error); |
| 254 | + $subscriber = new SuggestMissingPackageSubscriber(); |
| 255 | + $subscriber->onConsoleError($event); |
| 256 | + |
| 257 | + return $event->getError()->getMessage(); |
| 258 | + } |
| 259 | + |
229 | 260 | private function getKernel(array $bundles, $useDispatcher = false)
|
230 | 261 | {
|
231 | 262 | $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
|
0 commit comments