Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslaw-bogusz committed Jan 17, 2019
1 parent 8ffd1e6 commit 1d72a56
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1d72a56

Please sign in to comment.