diff --git a/console.rst b/console.rst index 30cd2dfb84a..cada5d73bba 100644 --- a/console.rst +++ b/console.rst @@ -216,21 +216,16 @@ console:: namespace Tests\AppBundle\Command; use AppBundle\Command\CreateUserCommand; - use Symfony\Component\Console\Application; - // use this if you're in the Symfony Framework - //use Symfony\Bundle\FrameworkBundle\Console\Application; + use Symfony\Bundle\FrameworkBundle\Console\Application; + use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; - class CreateUserCommandTest extends \PHPUnit_Framework_TestCase + class CreateUserCommandTest extends KernelTestCase { public function testExecute() { - $application = new Application(); - - // if you're in the Symfony framework, do this instead - // extend the KernelTestCase class - // self::bootKernel(); - // $application = new Application(self::$kernel); + self::bootKernel(); + $application = new Application(self::$kernel); $application->add(new CreateUserCommand()); @@ -259,6 +254,12 @@ console:: You can also test a whole console application by using :class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`. +.. note:: + + When using the Console component in a standalone project, use + :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`::