Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cad4d3f

Browse filesBrowse files
committed
bug #4582 Completed the needed context to successfully test commands with Helpers (peterrehm)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #4582). Discussion ---------- Completed the needed context to successfully test commands with Helpers | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | #4581 As mentioned in symfony/symfony#12798 the explanation about the initialization is not clear. Therefore I have added the needed context and a reference to the related cookbook article. Commits ------- a94bd71 Completed the needed context to successfully test commands
2 parents 3f3464f + a94bd71 commit cad4d3f
Copy full SHA for cad4d3f

File tree

Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed

‎components/console/helpers/dialoghelper.rst

Copy file name to clipboardExpand all lines: components/console/helpers/dialoghelper.rst
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,18 @@ Testing a Command which Expects Input
253253
If you want to write a unit test for a command which expects some kind of input
254254
from the command line, you need to overwrite the HelperSet used by the command::
255255

256+
use Symfony\Component\Console\Application;
256257
use Symfony\Component\Console\Helper\DialogHelper;
257258
use Symfony\Component\Console\Helper\HelperSet;
259+
use Symfony\Component\Console\Tester\CommandTester;
258260

259261
// ...
260262
public function testExecute()
261263
{
262264
// ...
265+
$application = new Application();
266+
$application->add(new MyCommand());
267+
$command = $application->find('my:command:name');
263268
$commandTester = new CommandTester($command);
264269

265270
$dialog = $command->getHelper('dialog');
@@ -285,3 +290,8 @@ By setting the input stream of the ``DialogHelper``, you imitate what the
285290
console would do internally with all user input through the cli. This way
286291
you can test any user interaction (even complex ones) by passing an appropriate
287292
input stream.
293+
294+
.. seealso::
295+
296+
You find more information about testing commands in the console component
297+
docs about :ref:`testing console commands <component-console-testing-commands>`.

‎components/console/introduction.rst

Copy file name to clipboardExpand all lines: components/console/introduction.rst
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ tools capable of helping you with different tasks:
377377
* :doc:`/components/console/helpers/progresshelper`: shows a progress bar
378378
* :doc:`/components/console/helpers/tablehelper`: displays tabular data as a table
379379

380+
.. _component-console-testing-commands:
381+
380382
Testing Commands
381383
----------------
382384

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.