Пример #1
0
 public function testPassedCallbackIsExecuted()
 {
     $helper = new ProcessHelper();
     $helper->setHelperSet(new HelperSet(array(new DebugFormatterHelper())));
     $output = $this->getOutputStream(StreamOutput::VERBOSITY_NORMAL);
     $executed = false;
     $callback = function () use(&$executed) {
         $executed = true;
     };
     $helper->run($output, 'php -r "echo 42;"', null, $callback);
     $this->assertTrue($executed);
 }
Пример #2
0
 /**
  * @param string $command
  * @param string $errorMessage
  * @return bool
  */
 protected function runCommand($command, $errorMessage)
 {
     $process = $this->processHelper->run($this->output, $command);
     if ($process->isSuccessful()) {
         $this->output->writeln('    <info>Success!</info>');
         return true;
     } else {
         if ($this->output->isVerbose()) {
             return false;
         }
         $this->output->writeln('    <error>' . $errorMessage . '</error>  Run this command with -vvv to see specific error info.');
         return false;
     }
 }
Пример #3
0
 /**
  * Execute a bash command.
  *
  * @param array $command
  * @param bool  $showOutput
  *
  * @return string
  */
 protected function execute(array $command, $showOutput = true)
 {
     $helper = new ProcessHelper();
     $helper->setHelperSet(new HelperSet(['debug_formatter' => new DebugFormatterHelper()]));
     // Compute new verbosity
     $previousVerbosity = $this->output->getVerbosity();
     $verbosity = $showOutput ? OutputInterface::VERBOSITY_DEBUG : OutputInterface::VERBOSITY_QUIET;
     // Execute command with defined verbosity
     $this->output->setVerbosity($verbosity);
     $process = $helper->run($this->output, $command);
     $this->output->setVerbosity($previousVerbosity);
     return $process->getOutput();
 }
Пример #4
0
 /**
  * @inheritDoc
  */
 public function diagnose()
 {
     $this->processHelper->run($this->output, $this->process);
     $processOutput = $this->process->getOutput();
     return $this->transformer->transform($processOutput);
 }
Пример #5
0
 /**
  * @param string|array|Process $cmd   An instance of Process or an array of arguments to escape and run or a command to run
  * @param string|null          $error An error message that must be displayed if something went wrong
  *
  * @return Process
  */
 public function run($cmd, $error = null)
 {
     return $this->helper->run($this->output, $cmd, $error);
 }
Пример #6
0
 /**
  * Runs an external process.
  *
  * @param string|array|Process $cmd       An instance of Process or an array of arguments to escape and run or a command to run
  * @param string|null          $error     An error message that must be displayed if something went wrong
  * @param callable|null        $callback  A PHP callback to run whenever there is some
  *                                        output available on STDOUT or STDERR
  * @param int                  $verbosity The threshold for verbosity
  *
  * @return Process The process that ran
  */
 public function run($cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
 {
     return $this->processHelper->run($this->output, $cmd, $error, $callback, $verbosity);
 }