Skip to content

Cookbook/Console/ConsoleCommand : Adding option/argument example in test #2793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions cookbook/console/console_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,25 @@ instead of

$command = $application->find('demo:greet');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$commandTester->execute(
array(
'command' => $command->getName(),
'name' => 'Fabien',
'--yell' => true,
)
);

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

// ...
}
}

.. note::

In the specific case above, the ``name`` parameter and the ``--yell`` option are not
mandatory for the command to work well, but they are shown for the example.

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\\WebTestCase`::
Expand All @@ -133,7 +144,13 @@ you can extend your test from

$command = $application->find('demo:greet');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$commandTester->execute(
array(
'command' => $command->getName(),
'name' => 'Fabien',
'--yell' => true,
)
);

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

Expand Down