Skip to content

Commit da6f7ed

Browse files
added tests
1 parent 8ffd1e6 commit da6f7ed

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Application;
15+
use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber;
1516
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1617
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Event\ConsoleErrorEvent;
19+
use Symfony\Component\Console\Exception\CommandNotFoundException;
1720
use Symfony\Component\Console\Input\ArrayInput;
1821
use Symfony\Component\Console\Input\InputInterface;
1922
use Symfony\Component\Console\Output\NullOutput;
@@ -226,6 +229,34 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
226229
$this->assertContains(trim('[WARNING] Some commands could not be registered:'), trim($display[1]));
227230
}
228231

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+
229260
private function getKernel(array $bundles, $useDispatcher = false)
230261
{
231262
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

0 commit comments

Comments
 (0)