| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Console\Tester; |
| 13 |
|
| 14 |
use Symfony\Component\Console\Command\Command; |
| 15 |
use Symfony\Component\Console\Input\ArrayInput; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class CommandTester |
| 24 |
{ |
| 25 |
use TesterTrait; |
| 26 |
|
| 27 |
private Command $command; |
| 28 |
|
| 29 |
public function __construct( |
| 30 |
callable|Command $command, |
| 31 |
) { |
| 32 |
$this->command = $command instanceof Command ? $command : new Command(null, $command); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function execute(array $input, array $options = []): int |
| 51 |
{ |
| 52 |
|
| 53 |
|
| 54 |
if (!isset($input['command']) |
| 55 |
&& (null !== $application = $this->command->getApplication()) |
| 56 |
&& $application->getDefinition()->hasArgument('command') |
| 57 |
) { |
| 58 |
$input = array_merge(['command' => $this->command->getName()], $input); |
| 59 |
} |
| 60 |
|
| 61 |
$this->input = new ArrayInput($input); |
| 62 |
|
| 63 |
$this->input->setStream(self::createStream($this->inputs)); |
| 64 |
|
| 65 |
if (isset($options['interactive'])) { |
| 66 |
$this->input->setInteractive($options['interactive']); |
| 67 |
} |
| 68 |
|
| 69 |
if (!isset($options['decorated'])) { |
| 70 |
$options['decorated'] = false; |
| 71 |
} |
| 72 |
|
| 73 |
$this->initOutput($options); |
| 74 |
|
| 75 |
return $this->statusCode = $this->command->run($this->input, $this->output); |
| 76 |
} |
| 77 |
} |