diff options
Diffstat (limited to 'vendor/symfony/console/Tester/CommandTester.php')
-rw-r--r-- | vendor/symfony/console/Tester/CommandTester.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/symfony/console/Tester/CommandTester.php b/vendor/symfony/console/Tester/CommandTester.php new file mode 100644 index 0000000..d39cde7 --- /dev/null +++ b/vendor/symfony/console/Tester/CommandTester.php | |||
@@ -0,0 +1,74 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
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 | * Eases the testing of console commands. | ||
19 | * | ||
20 | * @author Fabien Potencier <fabien@symfony.com> | ||
21 | * @author Robin Chalas <robin.chalas@gmail.com> | ||
22 | */ | ||
23 | class CommandTester | ||
24 | { | ||
25 | use TesterTrait; | ||
26 | |||
27 | public function __construct( | ||
28 | private Command $command, | ||
29 | ) { | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * Executes the command. | ||
34 | * | ||
35 | * Available execution options: | ||
36 | * | ||
37 | * * interactive: Sets the input interactive flag | ||
38 | * * decorated: Sets the output decorated flag | ||
39 | * * verbosity: Sets the output verbosity flag | ||
40 | * * capture_stderr_separately: Make output of stdOut and stdErr separately available | ||
41 | * | ||
42 | * @param array $input An array of command arguments and options | ||
43 | * @param array $options An array of execution options | ||
44 | * | ||
45 | * @return int The command exit code | ||
46 | */ | ||
47 | public function execute(array $input, array $options = []): int | ||
48 | { | ||
49 | // set the command name automatically if the application requires | ||
50 | // this argument and no command name was passed | ||
51 | if (!isset($input['command']) | ||
52 | && (null !== $application = $this->command->getApplication()) | ||
53 | && $application->getDefinition()->hasArgument('command') | ||
54 | ) { | ||
55 | $input = array_merge(['command' => $this->command->getName()], $input); | ||
56 | } | ||
57 | |||
58 | $this->input = new ArrayInput($input); | ||
59 | // Use an in-memory input stream even if no inputs are set so that QuestionHelper::ask() does not rely on the blocking STDIN. | ||
60 | $this->input->setStream(self::createStream($this->inputs)); | ||
61 | |||
62 | if (isset($options['interactive'])) { | ||
63 | $this->input->setInteractive($options['interactive']); | ||
64 | } | ||
65 | |||
66 | if (!isset($options['decorated'])) { | ||
67 | $options['decorated'] = false; | ||
68 | } | ||
69 | |||
70 | $this->initOutput($options); | ||
71 | |||
72 | return $this->statusCode = $this->command->run($this->input, $this->output); | ||
73 | } | ||
74 | } | ||