TYPO3  7.6
CommandTester.php
Go to the documentation of this file.
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 
19 
26 {
27  private $command;
28  private $input;
29  private $output;
30  private $statusCode;
31 
37  public function __construct(Command $command)
38  {
39  $this->command = $command;
40  }
41 
56  public function execute(array $input, array $options = array())
57  {
58  // set the command name automatically if the application requires
59  // this argument and no command name was passed
60  if (!isset($input['command'])
61  && (null !== $application = $this->command->getApplication())
62  && $application->getDefinition()->hasArgument('command')
63  ) {
64  $input = array_merge(array('command' => $this->command->getName()), $input);
65  }
66 
67  $this->input = new ArrayInput($input);
68  if (isset($options['interactive'])) {
69  $this->input->setInteractive($options['interactive']);
70  }
71 
72  $this->output = new StreamOutput(fopen('php://memory', 'w', false));
73  if (isset($options['decorated'])) {
74  $this->output->setDecorated($options['decorated']);
75  }
76  if (isset($options['verbosity'])) {
77  $this->output->setVerbosity($options['verbosity']);
78  }
79 
80  return $this->statusCode = $this->command->run($this->input, $this->output);
81  }
82 
90  public function getDisplay($normalize = false)
91  {
92  rewind($this->output->getStream());
93 
94  $display = stream_get_contents($this->output->getStream());
95 
96  if ($normalize) {
97  $display = str_replace(PHP_EOL, "\n", $display);
98  }
99 
100  return $display;
101  }
102 
108  public function getInput()
109  {
110  return $this->input;
111  }
112 
118  public function getOutput()
119  {
120  return $this->output;
121  }
122 
128  public function getStatusCode()
129  {
130  return $this->statusCode;
131  }
132 }