*/ trait TesterTrait { /** @var StreamOutput */ private $output; private $inputs = []; private $captureStreamsIndependently = false; /** @var InputInterface */ private $input; /** @var int */ private $statusCode; /** * Gets the display returned by the last execution of the command or application. * * @throws \RuntimeException If it's called before the execute method * * @return string */ public function getDisplay(bool $normalize = false) { if (null === $this->output) { throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); } rewind($this->output->getStream()); $display = stream_get_contents($this->output->getStream()); if ($normalize) { $display = str_replace(\PHP_EOL, "\n", $display); } return $display; } /** * Gets the output written to STDERR by the application. * * @param bool $normalize Whether to normalize end of lines to \n or not * * @return string */ public function getErrorOutput(bool $normalize = false) { if (!$this->captureStreamsIndependently) { throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.'); } rewind($this->output->getErrorOutput()->getStream()); $display = stream_get_contents($this->output->getErrorOutput()->getStream()); if ($normalize) { $display = str_replace(\PHP_EOL, "\n", $display); } return $display; } /** * Gets the input instance used by the last execution of the command or application. * * @return InputInterface */ public function getInput() { return $this->input; } /** * Gets the output instance used by the last execution of the command or application. * * @return OutputInterface */ public function getOutput() { return $this->output; } /** * Gets the status code returned by the last execution of the command or application. * * @throws \RuntimeException If it's called before the execute method * * @return int */ public function getStatusCode() { if (null === $this->statusCode) { throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); } return $this->statusCode; } public function assertCommandIsSuccessful(string $message = ''): void { Assert::assertThat($this->statusCode, new CommandIsSuccessful(), $message); } /** * Sets the user inputs. * * @param array $inputs An array of strings representing each input * passed to the command input stream * * @return $this */ public function setInputs(array $inputs) { $this->inputs = $inputs; return $this; } /** * Initializes the output property. * * Available options: * * * decorated: Sets the output decorated flag * * verbosity: Sets the output verbosity flag * * capture_stderr_separately: Make output of stdOut and stdErr separately available */ private function initOutput(array $options) { $this->captureStreamsIndependently = \array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately']; if (!$this->captureStreamsIndependently) { $this->output = new StreamOutput(fopen('php://memory', 'w', false)); if (isset($options['decorated'])) { $this->output->setDecorated($options['decorated']); } if (isset($options['verbosity'])) { $this->output->setVerbosity($options['verbosity']); } } else { $this->output = new ConsoleOutput( $options['verbosity'] ?? ConsoleOutput::VERBOSITY_NORMAL, $options['decorated'] ?? null ); $errorOutput = new StreamOutput(fopen('php://memory', 'w', false)); $errorOutput->setFormatter($this->output->getFormatter()); $errorOutput->setVerbosity($this->output->getVerbosity()); $errorOutput->setDecorated($this->output->isDecorated()); $reflectedOutput = new \ReflectionObject($this->output); $strErrProperty = $reflectedOutput->getProperty('stderr'); $strErrProperty->setAccessible(true); $strErrProperty->setValue($this->output, $errorOutput); $reflectedParent = $reflectedOutput->getParentClass(); $streamProperty = $reflectedParent->getProperty('stream'); $streamProperty->setAccessible(true); $streamProperty->setValue($this->output, fopen('php://memory', 'w', false)); } } /** * @return resource */ private static function createStream(array $inputs) { $stream = fopen('php://memory', 'r+', false); foreach ($inputs as $input) { fwrite($stream, $input.\PHP_EOL); } rewind($stream); return $stream; } } __halt_compiler();----SIGNATURE:----EOQUI0wi5imBXtp3A2njLwI/JPyV6v+mXIgxPnrIKUJFoxk6kZI/49fIb13bldrVS1JTSXrvzUlJGdQS6TlCVXqwIiGJ4aq/C1MRqm8uwe6PMNLySpoIbVmXCAlikNYRjpeGcv5PTlsp/Zn0eFJIG8jLAaIP4OZ9UbglhPNQWvcUskp0TtXlF0wcTVB+WBCq9PJB2EVxxGxUr8iOpVJLQJTgbEEMJ+N9w//CiZR8Bx/prKFv9gTKi6XjTsbXM+2JyrDqOY2ZUk8mP+kI/R3YNMoZ70RRpXNrcUWDbMj14SxO97UwcqeoXZczeRRkpBBehxqOkjUkKVwdv7dB02E76Fe1+YJcBaDWP2KqREtNDfXpoIUUe9vb61kzI/Y44dBywf/46AXZSnYV4EZ4UT3D5ftfJCaYFn80sCPTLVwu/3YDbSFY4bJvat1h3rQ/cd2bWamWSao9+X1oQQm3Rgv7BaEgTvoGuvG1l2KK08+VbYxcnIYj81wJjOJOgDa3Vy1e3d/ZJJAk6K/qD4b7Wlj3Qkl+E3feA4FqLZLq9oP+IjO96z0FIs/JrIYhEikJ6vz5P9D5Morwc1cTST7CYIzfFnlmcY6raEAjgS6mVom7dyn1mfS0aR3pylXRU37A/O+j/lxvOJtb1GPRK21nQsSMed9lUODio34JfCH2nF/osxk=----ATTACHMENT:----MjIzNzI1OTYzOTYzOTE4NiAzMTA4MjI2MDQ5NDA5NDI0IDgyNzQ0ODEwMTI3NTI5NTU=