-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Labels
Description
Symfony version(s) affected: v5.1.2
Description
I'm testing a SingleCommandApplication with CommandTester(PHPUnit).
However, the execution result cannot be received because it is exit
.
I think this is because autoExit
is true
.
If possible, I want to run setAutoExit(false)
from the test code.
How to reproduce
<?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;
class MainCommand extends SingleCommandApplication
{
public function __construct()
{
parent::__construct('Test');
$this->setUp();
}
private function setUp()
{
$this
->setCode(
function (InputInterface $input, OutputInterface $output) {
return Command::SUCCESS;
}
);
}
}
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
class MainCommandTest extends TestCase
{
public function test()
{
$command = new \MainCommand();
$commandTester = new CommandTester($command);
$commandTester->execute([]);
self::assertEquals(Command::SUCCESS, $commandTester->getStatusCode());
}
}