Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ApplicationTester.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Console\Tester;
013
014 use Symfony\Component\Console\Application;
015 use Symfony\Component\Console\Input\ArrayInput;
016 use Symfony\Component\Console\Input\InputInterface;
017 use Symfony\Component\Console\Output\ConsoleOutput;
018 use Symfony\Component\Console\Output\OutputInterface;
019 use Symfony\Component\Console\Output\StreamOutput;
020
021 /**
022 * Eases the testing of console applications.
023 *
024 * When testing an application, don't forget to disable the auto exit flag:
025 *
026 * $application = new Application();
027 * $application->setAutoExit(false);
028 *
029 * @author Fabien Potencier <fabien@symfony.com>
030 */
031 class ApplicationTester
032 {
033 private $application;
034 private $input;
035 private $statusCode;
036 /**
037 * @var OutputInterface
038 */
039 private $output;
040 private $captureStreamsIndependently = false;
041
042 public function __construct(Application $application)
043 {
044 $this->application = $application;
045 }
046
047 /**
048 * Executes the application.
049 *
050 * Available options:
051 *
052 * * interactive: Sets the input interactive flag
053 * * decorated: Sets the output decorated flag
054 * * verbosity: Sets the output verbosity flag
055 * * capture_stderr_separately: Make output of stdOut and stdErr separately available
056 *
057 * @param array $input An array of arguments and options
058 * @param array $options An array of options
059 *
060 * @return int The command exit code
061 */
062 public function run(array $input, $options = [])
063 {
064 $this->input = new ArrayInput($input);
065 if (isset($options['interactive'])) {
066 $this->input->setInteractive($options['interactive']);
067 }
068
069 $this->captureStreamsIndependently = \array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately'];
070 if (!$this->captureStreamsIndependently) {
071 $this->output = new StreamOutput(fopen('php://memory', 'w', false));
072 if (isset($options['decorated'])) {
073 $this->output->setDecorated($options['decorated']);
074 }
075 if (isset($options['verbosity'])) {
076 $this->output->setVerbosity($options['verbosity']);
077 }
078 } else {
079 $this->output = new ConsoleOutput(
080 isset($options['verbosity']) ? $options['verbosity'] : ConsoleOutput::VERBOSITY_NORMAL,
081 isset($options['decorated']) ? $options['decorated'] : null
082 );
083
084 $errorOutput = new StreamOutput(fopen('php://memory', 'w', false));
085 $errorOutput->setFormatter($this->output->getFormatter());
086 $errorOutput->setVerbosity($this->output->getVerbosity());
087 $errorOutput->setDecorated($this->output->isDecorated());
088
089 $reflectedOutput = new \ReflectionObject($this->output);
090 $strErrProperty = $reflectedOutput->getProperty('stderr');
091 $strErrProperty->setAccessible(true);
092 $strErrProperty->setValue($this->output, $errorOutput);
093
094 $reflectedParent = $reflectedOutput->getParentClass();
095 $streamProperty = $reflectedParent->getProperty('stream');
096 $streamProperty->setAccessible(true);
097 $streamProperty->setValue($this->output, fopen('php://memory', 'w', false));
098 }
099
100 return $this->statusCode = $this->application->run($this->input, $this->output);
101 }
102
103 /**
104 * Gets the display returned by the last execution of the application.
105 *
106 * @param bool $normalize Whether to normalize end of lines to \n or not
107 *
108 * @return string The display
109 */
110 public function getDisplay($normalize = false)
111 {
112 rewind($this->output->getStream());
113
114 $display = stream_get_contents($this->output->getStream());
115
116 if ($normalize) {
117 $display = str_replace(\PHP_EOL, "\n", $display);
118 }
119
120 return $display;
121 }
122
123 /**
124 * Gets the output written to STDERR by the application.
125 *
126 * @param bool $normalize Whether to normalize end of lines to \n or not
127 *
128 * @return string
129 */
130 public function getErrorOutput($normalize = false)
131 {
132 if (!$this->captureStreamsIndependently) {
133 throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.');
134 }
135
136 rewind($this->output->getErrorOutput()->getStream());
137
138 $display = stream_get_contents($this->output->getErrorOutput()->getStream());
139
140 if ($normalize) {
141 $display = str_replace(\PHP_EOL, "\n", $display);
142 }
143
144 return $display;
145 }
146
147 /**
148 * Gets the input instance used by the last execution of the application.
149 *
150 * @return InputInterface The current input instance
151 */
152 public function getInput()
153 {
154 return $this->input;
155 }
156
157 /**
158 * Gets the output instance used by the last execution of the application.
159 *
160 * @return OutputInterface The current output instance
161 */
162 public function getOutput()
163 {
164 return $this->output;
165 }
166
167 /**
168 * Gets the status code returned by the last execution of the application.
169 *
170 * @return int The status code
171 */
172 public function getStatusCode()
173 {
174 return $this->statusCode;
175 }
176 }
177