From e0484d6f845a641e41c4b1598602c7c393668280 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 6 Aug 2018 10:55:04 -0400 Subject: [PATCH] You do not need to re-add the command --- console.rst | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/console.rst b/console.rst index 59c59e05f06..0effdcc29f0 100644 --- a/console.rst +++ b/console.rst @@ -276,11 +276,9 @@ console:: { public function testExecute() { - $kernel = self::bootKernel(); + $kernel = static::createKernel(); $application = new Application($kernel); - $application->add(new CreateUserCommand()); - $command = $application->find('app:create-user'); $commandTester = new CommandTester($command); $commandTester->execute(array( @@ -312,39 +310,6 @@ console:: :class:`Symfony\\Component\\Console\\Application ` and extend the normal ``\PHPUnit\Framework\TestCase``. -To be able to use the fully set up service container for your console tests -you can extend your test from -:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase`:: - - // ... - use Symfony\Component\Console\Tester\CommandTester; - use Symfony\Bundle\FrameworkBundle\Console\Application; - use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; - - class CreateUserCommandTest extends KernelTestCase - { - public function testExecute() - { - $kernel = static::createKernel(); - $kernel->boot(); - - $application = new Application($kernel); - $application->add(new CreateUserCommand()); - - $command = $application->find('app:create-user'); - $commandTester = new CommandTester($command); - $commandTester->execute(array( - 'command' => $command->getName(), - 'username' => 'Wouter', - )); - - $output = $commandTester->getDisplay(); - $this->assertContains('Username: Wouter', $output); - - // ... - } - } - Learn More ----------