/** * @expectedException \Symfony\Component\Process\Exception\ProcessFailedException */ public function testMustRunAllFail() { $helper = new ProcessHelper(); $helper->setHelperSet(new HelperSet([new DebugFormatterHelper()])); /** @var Process[] $processes */ $processes = [new Process('php -r "echo 42;"'), new Process('php -r "syntax error"'), new Process('php -r "echo 42;"')]; $execute = new Execute(new NullOutput(), $helper); $execute->mustRunAll($processes); }
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); }
/** * @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; } }
/** * 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(); }
/** * @inheritDoc */ public function diagnose() { $this->processHelper->run($this->output, $this->process); $processOutput = $this->process->getOutput(); return $this->transformer->transform($processOutput); }
/** * @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 mustRun($cmd, $error = null) { return $this->helper->mustRun($this->output, $cmd, $error); }
/** * Wraps a Process callback to add debugging output. * * @param Process $process The Process * @param callable|null $callback A PHP callable * * @return callable */ public function wrapCallback(Process $process, callable $callback = null) { return $this->processHelper->wrapCallback($this->output, $process, $callback); }