Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/console/Tester/CommandTester.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
11 | 11 |
12 namespace Symfony\Component\Console\Tester; | 12 namespace Symfony\Component\Console\Tester; |
13 | 13 |
14 use Symfony\Component\Console\Command\Command; | 14 use Symfony\Component\Console\Command\Command; |
15 use Symfony\Component\Console\Input\ArrayInput; | 15 use Symfony\Component\Console\Input\ArrayInput; |
16 use Symfony\Component\Console\Output\StreamOutput; | |
17 use Symfony\Component\Console\Input\InputInterface; | 16 use Symfony\Component\Console\Input\InputInterface; |
18 use Symfony\Component\Console\Output\OutputInterface; | 17 use Symfony\Component\Console\Output\OutputInterface; |
18 use Symfony\Component\Console\Output\StreamOutput; | |
19 | 19 |
20 /** | 20 /** |
21 * Eases the testing of console commands. | 21 * Eases the testing of console commands. |
22 * | 22 * |
23 * @author Fabien Potencier <fabien@symfony.com> | 23 * @author Fabien Potencier <fabien@symfony.com> |
26 class CommandTester | 26 class CommandTester |
27 { | 27 { |
28 private $command; | 28 private $command; |
29 private $input; | 29 private $input; |
30 private $output; | 30 private $output; |
31 private $inputs = array(); | 31 private $inputs = []; |
32 private $statusCode; | 32 private $statusCode; |
33 | 33 |
34 public function __construct(Command $command) | 34 public function __construct(Command $command) |
35 { | 35 { |
36 $this->command = $command; | 36 $this->command = $command; |
48 * @param array $input An array of command arguments and options | 48 * @param array $input An array of command arguments and options |
49 * @param array $options An array of execution options | 49 * @param array $options An array of execution options |
50 * | 50 * |
51 * @return int The command exit code | 51 * @return int The command exit code |
52 */ | 52 */ |
53 public function execute(array $input, array $options = array()) | 53 public function execute(array $input, array $options = []) |
54 { | 54 { |
55 // set the command name automatically if the application requires | 55 // set the command name automatically if the application requires |
56 // this argument and no command name was passed | 56 // this argument and no command name was passed |
57 if (!isset($input['command']) | 57 if (!isset($input['command']) |
58 && (null !== $application = $this->command->getApplication()) | 58 && (null !== $application = $this->command->getApplication()) |
59 && $application->getDefinition()->hasArgument('command') | 59 && $application->getDefinition()->hasArgument('command') |
60 ) { | 60 ) { |
61 $input = array_merge(array('command' => $this->command->getName()), $input); | 61 $input = array_merge(['command' => $this->command->getName()], $input); |
62 } | 62 } |
63 | 63 |
64 $this->input = new ArrayInput($input); | 64 $this->input = new ArrayInput($input); |
65 if ($this->inputs) { | 65 if ($this->inputs) { |
66 $this->input->setStream(self::createStream($this->inputs)); | 66 $this->input->setStream(self::createStream($this->inputs)); |
146 | 146 |
147 private static function createStream(array $inputs) | 147 private static function createStream(array $inputs) |
148 { | 148 { |
149 $stream = fopen('php://memory', 'r+', false); | 149 $stream = fopen('php://memory', 'r+', false); |
150 | 150 |
151 fwrite($stream, implode(PHP_EOL, $inputs)); | 151 foreach ($inputs as $input) { |
152 fwrite($stream, $input.PHP_EOL); | |
153 } | |
154 | |
152 rewind($stream); | 155 rewind($stream); |
153 | 156 |
154 return $stream; | 157 return $stream; |
155 } | 158 } |
156 } | 159 } |