[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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\Input\InputInterface; 17 use Symfony\Component\Console\Output\OutputInterface; 18 use Symfony\Component\Console\Output\StreamOutput; 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 private $statusCode; 31 32 public function __construct(Command $command) 33 { 34 $this->command = $command; 35 } 36 37 /** 38 * Executes the command. 39 * 40 * Available execution options: 41 * 42 * * interactive: Sets the input interactive flag 43 * * decorated: Sets the output decorated flag 44 * * verbosity: Sets the output verbosity flag 45 * 46 * @param array $input An array of command arguments and options 47 * @param array $options An array of execution options 48 * 49 * @return int The command exit code 50 */ 51 public function execute(array $input, array $options = array()) 52 { 53 // set the command name automatically if the application requires 54 // this argument and no command name was passed 55 if (!isset($input['command']) 56 && (null !== $application = $this->command->getApplication()) 57 && $application->getDefinition()->hasArgument('command') 58 ) { 59 $input = array_merge(array('command' => $this->command->getName()), $input); 60 } 61 62 $this->input = new ArrayInput($input); 63 if (isset($options['interactive'])) { 64 $this->input->setInteractive($options['interactive']); 65 } 66 67 $this->output = new StreamOutput(fopen('php://memory', 'w', false)); 68 $this->output->setDecorated(isset($options['decorated']) ? $options['decorated'] : false); 69 if (isset($options['verbosity'])) { 70 $this->output->setVerbosity($options['verbosity']); 71 } 72 73 return $this->statusCode = $this->command->run($this->input, $this->output); 74 } 75 76 /** 77 * Gets the display returned by the last execution of the command. 78 * 79 * @param bool $normalize Whether to normalize end of lines to \n or not 80 * 81 * @return string The display 82 */ 83 public function getDisplay($normalize = false) 84 { 85 rewind($this->output->getStream()); 86 87 $display = stream_get_contents($this->output->getStream()); 88 89 if ($normalize) { 90 $display = str_replace(PHP_EOL, "\n", $display); 91 } 92 93 return $display; 94 } 95 96 /** 97 * Gets the input instance used by the last execution of the command. 98 * 99 * @return InputInterface The current input instance 100 */ 101 public function getInput() 102 { 103 return $this->input; 104 } 105 106 /** 107 * Gets the output instance used by the last execution of the command. 108 * 109 * @return OutputInterface The current output instance 110 */ 111 public function getOutput() 112 { 113 return $this->output; 114 } 115 116 /** 117 * Gets the status code returned by the last execution of the application. 118 * 119 * @return int The status code 120 */ 121 public function getStatusCode() 122 { 123 return $this->statusCode; 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |