[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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 use Symfony\Component\Console\Output\StreamOutput; 17 use Symfony\Component\Console\Input\InputInterface; 18 use Symfony\Component\Console\Output\OutputInterface; 19 20 /** 21 * Eases the testing of console commands. 22 * 23 * @author Fabien Potencier <fabien@symfony.com> 24 */ 25 class CommandTester 26 { 27 private $command; 28 private $input; 29 private $output; 30 31 /** 32 * Constructor. 33 * 34 * @param Command $command A Command instance to test. 35 */ 36 public function __construct(Command $command) 37 { 38 $this->command = $command; 39 } 40 41 /** 42 * Executes the command. 43 * 44 * Available execution options: 45 * 46 * * interactive: Sets the input interactive flag 47 * * decorated: Sets the output decorated flag 48 * * verbosity: Sets the output verbosity flag 49 * 50 * @param array $input An array of command arguments and options 51 * @param array $options An array of execution options 52 * 53 * @return int The command exit code 54 */ 55 public function execute(array $input, array $options = array()) 56 { 57 $this->input = new ArrayInput($input); 58 if (isset($options['interactive'])) { 59 $this->input->setInteractive($options['interactive']); 60 } 61 62 $this->output = new StreamOutput(fopen('php://memory', 'w', false)); 63 if (isset($options['decorated'])) { 64 $this->output->setDecorated($options['decorated']); 65 } 66 if (isset($options['verbosity'])) { 67 $this->output->setVerbosity($options['verbosity']); 68 } 69 70 return $this->command->run($this->input, $this->output); 71 } 72 73 /** 74 * Gets the display returned by the last execution of the command. 75 * 76 * @param bool $normalize Whether to normalize end of lines to \n or not 77 * 78 * @return string The display 79 */ 80 public function getDisplay($normalize = false) 81 { 82 rewind($this->output->getStream()); 83 84 $display = stream_get_contents($this->output->getStream()); 85 86 if ($normalize) { 87 $display = str_replace(PHP_EOL, "\n", $display); 88 } 89 90 return $display; 91 } 92 93 /** 94 * Gets the input instance used by the last execution of the command. 95 * 96 * @return InputInterface The current input instance 97 */ 98 public function getInput() 99 { 100 return $this->input; 101 } 102 103 /** 104 * Gets the output instance used by the last execution of the command. 105 * 106 * @return OutputInterface The current output instance 107 */ 108 public function getOutput() 109 { 110 return $this->output; 111 } 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |