public function testForProcessVerboseWithTrace() { $process = $this->getMockBuilder('Symfony\\Component\\Process\\Process')->disableOriginalConstructor()->getMock(); $process->expects($this->any())->method('getCommandLine')->willReturn('puli do something'); $process->expects($this->any())->method('getExitCode')->willReturn(1); $process->expects($this->any())->method('getErrorOutput')->willReturn($output = <<<EOF [ErrorException] preg_match(): Compilation failed Exception trace: () EOF ); $exception = PuliRunnerException::forProcess($process); $this->assertSame('puli do something', $exception->getCommand()); $this->assertSame(1, $exception->getExitCode()); $this->assertSame('ErrorException: preg_match(): Compilation failed', $exception->getShortError()); $this->assertSame($output, $exception->getFullError()); }
/** * Runs a Puli command. * * @param string $command The Puli command to run. * * @return string The lines of the output. */ public function run($command) { // Disable colorization so that we can process the output // Enable exception traces by using the "-vv" switch $fullCommand = sprintf('%s %s --no-ansi -vv', $this->puli, $command); $process = new Process($fullCommand); $process->run(); if (!$process->isSuccessful()) { throw PuliRunnerException::forProcess($process); } // Normalize line endings across systems return str_replace("\r\n", "\n", $process->getOutput()); }
/** * Runs a Puli command. * * @param string $command The Puli command to run. * @param string[] $args Arguments to quote and insert into the command. * For each key "key" in this array, the placeholder * "%key%" should be present in the command string. * * @return string The lines of the output. */ public function run($command, array $args = array()) { $replacements = array(); foreach ($args as $key => $arg) { $replacements['%' . $key . '%'] = ProcessUtils::escapeArgument($arg); } // Disable colorization so that we can process the output // Enable exception traces by using the "-vv" switch $fullCommand = sprintf('%s %s --no-ansi -vv', $this->puli, strtr($command, $replacements)); $process = new Process($fullCommand); $process->run(); if (!$process->isSuccessful()) { throw PuliRunnerException::forProcess($process); } // Normalize line endings across systems return str_replace("\r\n", "\n", $process->getOutput()); }
private function printWarning(IOInterface $io, $message, PuliRunnerException $exception = null) { if (!$exception) { $reasonPhrase = ''; } elseif ($io->isVerbose()) { $reasonPhrase = $exception->getFullError(); } else { $reasonPhrase = $exception->getShortError(); } $io->writeError(sprintf('<warning>Warning: %s%s</warning>', $message, $reasonPhrase ? ': ' . $reasonPhrase : '.')); }