Skip to content

Commit

Permalink
Changes to standalone console testing section
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmiller-zz committed Feb 14, 2012
1 parent 95e0a78 commit 200ab7e
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions components/console.rst
Expand Up @@ -247,13 +247,9 @@ console::
{
public function testExecute()
{
// mock the Kernel or create one depending on your needs
$application = new Application($kernel);
$application->add(new GreetCommand());

$command = $application->find('demo:greet');
$command = new GreetCommand();
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$commandTester->execute();

$this->assertRegExp('/.../', $commandTester->getDisplay());

Expand All @@ -265,6 +261,29 @@ The :method:`Symfony\\Component\\Console\\Tester\\CommandTester::getDisplay`
method returns what would have been displayed during a normal call from the
console.

You can test sending arguments and options to the command by passing them
as an array to the :method:`Symfony\\Component\\Console\\Tester\\CommandTester::getDisplay`
method::

use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Acme\DemoBundle\Command\GreetCommand;

class ListCommandTest extends \PHPUnit_Framework_TestCase
{

//--

public function testNameIsOutput()
{
$command = new GreetCommand();
$commandTester = new CommandTester($command);
$commandTester->execute(array('name' => 'Fabien'));

$this->assertRegExp('/Fabien/', $commandTester->getDisplay());
}
}

.. tip::

You can also test a whole console application by using
Expand Down

0 comments on commit 200ab7e

Please sign in to comment.