From 1d72a560f1e02bb8543469dd2d66b074efc5d986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Bogusz?= Date: Thu, 17 Jan 2019 12:24:17 +0100 Subject: [PATCH] added tests --- .../Tests/Console/ApplicationTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index 6662efd4a40a0..17f3a941e0aba 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -12,8 +12,11 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Console; use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Event\ConsoleErrorEvent; +use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\NullOutput; @@ -226,6 +229,34 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd() $this->assertContains(trim('[WARNING] Some commands could not be registered:'), trim($display[1])); } + public function testSuggestingPackagesWithExactMatch() + { + $result = $this->createEventForSuggestingPackages('server:dump', []); + $this->assertRegExp("/You may be looking for a command provided by the/", $result); + } + + public function testSuggestingPackagesWithPartialMatchAndNoAlternatives() + { + $result = $this->createEventForSuggestingPackages('server', []); + $this->assertRegExp("/You may be looking for a command provided by the/", $result); + } + + public function testSuggestingPackagesWithPartialMatchAndAlternatives() + { + $result = $this->createEventForSuggestingPackages('server', ['server:run']); + $this->assertNotRegExp("/You may be looking for a command provided by the/", $result); + } + + private function createEventForSuggestingPackages(string $command, array $alternatives = []): string + { + $error = new CommandNotFoundException('', $alternatives); + $event = new ConsoleErrorEvent(new ArrayInput([$command]), new NullOutput(), $error); + $subscriber = new SuggestMissingPackageSubscriber(); + $subscriber->onConsoleError($event); + + return $event->getError()->getMessage(); + } + private function getKernel(array $bundles, $useDispatcher = false) { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();