Skip to content

Commit ecbeae8

Browse files
committed
Merge pull request #2793 from gregquat/patch-18
Cookbook/Console/ConsoleCommand : Adding option/argument example in test
2 parents 22ffc22 + c5682f7 commit ecbeae8

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cookbook/console/console_command.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,25 @@ instead of
104104

105105
$command = $application->find('demo:greet');
106106
$commandTester = new CommandTester($command);
107-
$commandTester->execute(array('command' => $command->getName()));
107+
$commandTester->execute(
108+
array(
109+
'command' => $command->getName(),
110+
'name' => 'Fabien',
111+
'--yell' => true,
112+
)
113+
);
108114

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

111117
// ...
112118
}
113119
}
114120

121+
.. note::
122+
123+
In the specific case above, the ``name`` parameter and the ``--yell`` option are not
124+
mandatory for the command to work well, but they are shown for the example.
125+
115126
To be able to use the fully set up service container for your console tests
116127
you can extend your test from
117128
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\WebTestCase`::
@@ -133,7 +144,13 @@ you can extend your test from
133144

134145
$command = $application->find('demo:greet');
135146
$commandTester = new CommandTester($command);
136-
$commandTester->execute(array('command' => $command->getName()));
147+
$commandTester->execute(
148+
array(
149+
'command' => $command->getName(),
150+
'name' => 'Fabien',
151+
'--yell' => true,
152+
)
153+
);
137154

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

0 commit comments

Comments
 (0)