8000 minor #10154 [Command] No need to register the command manually (weav… · symfony/symfony-docs@f4c9872 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4c9872

Browse files
committed
minor #10154 [Command] No need to register the command manually (weaverryan)
This PR was merged into the 3.4 branch. Discussion ---------- [Command] No need to register the command manually Hey guys! Basically, when instantiating the `Application` from FrameworkBundle, you do not need to manually add the command manually. We also had a second, duplicated section that talked about testing with the kernel/container... but we do that already in the first code block. I think just got out of sync over years of updating & refactoring. I did test that we do NOT need to manually instantiate/add the command and we do NOT need to call `$kernel->boot()`. Commits ------- e0484d6 You do not need to re-add the command
2 parents eee8a30 + e0484d6 commit f4c9872

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

console.rst

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,9 @@ console::
276276
{
277277
public function testExecute()
278278
{
279-
$kernel = self::bootKernel();
279+
$kernel = static::createKernel();
280280
$application = new Application($kernel);
281281

282-
$application->add(new CreateUserCommand());
283-
284282
$command = $application->find('app:create-user');
285283
$commandTester = new CommandTester($command);
286284
$commandTester->execute(array(
@@ -312,39 +310,6 @@ console::
312310
:class:`Symfony\\Component\\Console\\Application <Symfony\\Component\\Console\\Application>`
313311
and extend the normal ``\PHPUnit\Framework\TestCase``.
314312

315-
To be able to use the fully set up service container for your console tests
316-
you can extend your test from
317-
:class:`Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase`::
318-
319-
// ...
320-
use Symfony\Component\Console\Tester\CommandTester;
321-
use Symfony\Bundle\FrameworkBundle\Console\Application;
322-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
323-
324-
class CreateUserCommandTest extends KernelTestCase
325-
{
326-
public function testExecute()
327-
{
328-
$kernel = static::createKernel();
329-
$kernel->boot();
330-
331-
$application = new Application($kernel);
332-
$application->add(new CreateUserCommand());
333-
334-
$command = $application->find('app:create-user');
335-
$commandTester = new CommandTester($command);
336-
$commandTester->execute(array(
337-
'command' => $command->getName(),
338-
'username' => 'Wouter',
339-
));
340-
341-
$output = $commandTester->getDisplay();
342-
$this->assertContains('Username: Wouter', $output);
343-
344-
// ...
345-
}
346-
}
347-
348313
Learn More
349314
----------
350315

0 commit comments

Comments
 (0)
0