[ 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\Application; 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 applications. 22 * 23 * When testing an application, don't forget to disable the auto exit flag: 24 * 25 * $application = new Application(); 26 * $application->setAutoExit(false); 27 * 28 * @author Fabien Potencier <fabien@symfony.com> 29 */ 30 class ApplicationTester 31 { 32 private $application; 33 private $input; 34 private $output; 35 private $statusCode; 36 37 public function __construct(Application $application) 38 { 39 $this->application = $application; 40 } 41 42 /** 43 * Executes the application. 44 * 45 * Available options: 46 * 47 * * interactive: Sets the input interactive flag 48 * * decorated: Sets the output decorated flag 49 * * verbosity: Sets the output verbosity flag 50 * 51 * @param array $input An array of arguments and options 52 * @param array $options An array of options 53 * 54 * @return int The command exit code 55 */ 56 public function run(array $input, $options = array()) 57 { 58 $this->input = new ArrayInput($input); 59 if (isset($options['interactive'])) { 60 $this->input->setInteractive($options['interactive']); 61 } 62 63 $this->output = new StreamOutput(fopen('php://memory', 'w', false)); 64 if (isset($options['decorated'])) { 65 $this->output->setDecorated($options['decorated']); 66 } 67 if (isset($options['verbosity'])) { 68 $this->output->setVerbosity($options['verbosity']); 69 } 70 71 return $this->statusCode = $this->application->run($this->input, $this->output); 72 } 73 74 /** 75 * Gets the display returned by the last execution of the application. 76 * 77 * @param bool $normalize Whether to normalize end of lines to \n or not 78 * 79 * @return string The display 80 */ 81 public function getDisplay($normalize = false) 82 { 83 rewind($this->output->getStream()); 84 85 $display = stream_get_contents($this->output->getStream()); 86 87 if ($normalize) { 88 $display = str_replace(PHP_EOL, "\n", $display); 89 } 90 91 return $display; 92 } 93 94 /** 95 * Gets the input instance used by the last execution of the application. 96 * 97 * @return InputInterface The current input instance 98 */ 99 public function getInput() 100 { 101 return $this->input; 102 } 103 104 /** 105 * Gets the output instance used by the last execution of the application. 106 * 107 * @return OutputInterface The current output instance 108 */ 109 public function getOutput() 110 { 111 return $this->output; 112 } 113 114 /** 115 * Gets the status code returned by the last execution of the application. 116 * 117 * @return int The status code 118 */ 119 public function getStatusCode() 120 { 121 return $this->statusCode; 122 } 123 }
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 |