getOutput() public method

Returns the current output of the process (STDOUT).
public getOutput ( ) : string
return string The process output
 /**
  * {@inheritdoc}
  */
 public function check()
 {
     if (!$this->isSuccessful()) {
         // on some systems stderr is used, but on others, it's not
         throw new LintingException($this->process->getErrorOutput() ?: $this->process->getOutput(), $this->process->getExitCode());
     }
 }
示例#2
0
 public function execute($template, array $parameters)
 {
     $bootstrap = $this->getBootstrapPath();
     if ($bootstrap && !file_exists($bootstrap)) {
         throw new \InvalidArgumentException(sprintf('Bootstrap file "%s" does not exist', $bootstrap));
     }
     if (!file_exists($template)) {
         throw new \RuntimeException(sprintf('Could not find script template "%s"', $template));
     }
     $parameters['bootstrap'] = $bootstrap;
     $tokens = array();
     foreach ($parameters as $key => $value) {
         $tokens['{{ ' . $key . ' }}'] = $value;
     }
     $templateBody = file_get_contents($template);
     $script = str_replace(array_keys($tokens), array_values($tokens), $templateBody);
     $scriptPath = tempnam(sys_get_temp_dir(), 'PhpBench');
     file_put_contents($scriptPath, $script);
     $process = new Process(PHP_BINARY . ' ' . $scriptPath);
     $process->run();
     unlink($scriptPath);
     if (false === $process->isSuccessful()) {
         throw new \RuntimeException(sprintf('Could not execute script: %s %s', $process->getErrorOutput(), $process->getOutput()));
     }
     $output = $process->getOutput();
     $result = json_decode($output, true);
     if (null === $result) {
         throw new \RuntimeException(sprintf('Could not decode return value from script from template "%s" (should be a JSON encoded string): %s', $template, $output));
     }
     return $result;
 }
示例#3
0
 /**
  * @dataProvider getTestFiles
  */
 public function testIntegration(\SplFileInfo $testFile)
 {
     $testData = $this->parseTestFile($testFile);
     $cmd = 'php ' . __DIR__ . '/../../../bin/composer --no-ansi ' . $testData['RUN'];
     $proc = new Process($cmd);
     $exitcode = $proc->run();
     if (isset($testData['EXPECT'])) {
         $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-ERROR'])) {
         $this->assertEquals($testData['EXPECT-ERROR'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-ERROR-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-ERROR-REGEX'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-EXIT-CODE'])) {
         $this->assertSame($testData['EXPECT-EXIT-CODE'], $exitcode);
     }
     // Clean up.
     $fs = new Filesystem();
     if (isset($testData['test_dir']) && is_dir($testData['test_dir'])) {
         $fs->removeDirectory($testData['test_dir']);
     }
 }
示例#4
0
 public function test(array $configurationFiles)
 {
     $path = rtrim(sys_get_temp_dir(), '/') . '/' . uniqid('nagadmin-test');
     mkdir($path);
     $checkResultPath = $path . '/checkresults';
     mkdir($checkResultPath, 0777);
     $logFilePath = '/dev/null';
     $configurationFiles[] = $this->createMainConfigFile($path, $configurationFiles, $checkResultPath, $logFilePath);
     $this->writer->write($path, $configurationFiles);
     try {
         $process = new Process('nagios --verify-config ' . escapeshellarg($path . '/nagios.cfg') . ' 2>&1');
         $process->setTimeout(10);
         $process->run();
         if (!$process->isSuccessful()) {
             throw new \RuntimeException($process->getOutput());
         }
         $isValid = true;
         $checkOutput = $process->getOutput();
     } catch (\RuntimeException $e) {
         $isValid = false;
         $checkOutput = $e->getMessage();
     }
     $this->writer->cleanup($path);
     rmdir($path);
     return array($isValid, $checkOutput);
 }
示例#5
0
 /**
  * @return string
  */
 public function compile()
 {
     $this->stopwatch->start('webpack.total');
     $this->stopwatch->start('webpack.prepare');
     // Recompile twig templates where its needed.
     $this->addSplitPoints();
     $this->addResolveConfig();
     // Write the webpack configuration file.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.config.js', $this->generator->getConfiguration());
     $this->profiler->set('compiler.performance.prepare', $this->stopwatch->stop('webpack.prepare')->getDuration());
     $this->stopwatch->start('webpack.compiler');
     $this->process->run();
     $output = $this->process->getOutput() . $this->process->getErrorOutput();
     $this->profiler->set('compiler.executed', true);
     $this->profiler->set('compiler.successful', strpos($output, 'Error:') === false);
     $this->profiler->set('compiler.last_output', $output);
     if ($this->profiler->get('compiler.successful')) {
         $this->tracker->rebuild();
     }
     // Finally, write some logging for later use.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.compiler.log', $output);
     $this->profiler->set('compiler.performance.compiler', $this->stopwatch->stop('webpack.compiler')->getDuration());
     $this->profiler->set('compiler.performance.total', $this->stopwatch->stop('webpack.total')->getDuration());
     return $output;
 }
示例#6
0
文件: Util.php 项目: fbone/mediboard4
 /**
  * Execute an SVN command
  *
  * @param string  $cmd       Command name (update, info, etc)
  * @param array   $arguments An array of argument (path, url, etc)
  * @param array   $options   An array of options
  * @param string  $path      Working directory
  * @param integer $timeout   Timeout
  *
  * @return string
  * @throws \Exception
  */
 public static function exec($cmd, $arguments = array(), $options = array(), $path = null, $output = false, $timeout = null)
 {
     if (!is_array($arguments)) {
         $arguments = array($arguments);
     }
     $arguments = array_map("escapeshellarg", $arguments);
     $new_options = array();
     foreach ($options as $key => $value) {
         $new_options[] = preg_replace("/[^-\\w]/", "", $key);
         if ($value !== true) {
             $new_options[] = escapeshellarg($value);
         }
     }
     $cmdline = "svn {$cmd} " . implode(" ", $arguments) . " " . implode(" ", $new_options);
     $process = new Process($cmdline, $path, null, null, $timeout);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new RuntimeException($process->getErrorOutput());
     }
     if ($output) {
         echo $process->getOutput();
         return null;
     }
     return $process->getOutput();
 }
示例#7
0
 /**
  * Executes a shell command.
  *
  * @param string $command
  *
  * @return $this
  */
 public function runShellCommand($command)
 {
     $this->process = new Process($command);
     $this->exitCode = $this->process->run();
     $this->stdOutput = $this->process->getOutput();
     $this->stdError = $this->process->getErrorOutput();
     return $this;
 }
 /**
  * @Then I see :output
  */
 public function iSeeInline($output)
 {
     $actual = trim($this->process->getOutput());
     $expected = trim($output);
     if ($expected !== $actual) {
         throw new \Exception(sprintf('"%s" != "%s"', $actual, $expected));
     }
 }
示例#9
0
 /**
  * @param Process $process
  */
 public function run(Process $process)
 {
     $this->logger->debug(sprintf('Webhook process started: "%s".', $command = $process->getCommandLine()));
     $process->run();
     if ($process->isSuccessful()) {
         $this->logger->debug(sprintf('Webhook process finished: "%s".', $command), ['output' => $process->getOutput()]);
     } else {
         $this->logger->error(sprintf('Webhook process errored: "%s".', $command), ['output' => $process->getOutput(), 'error' => $process->getErrorOutput()]);
     }
 }
示例#10
0
 /**
  * Returns the result for the command string.
  *
  * @param string  $command The command string.
  * @param string  $dir     The working directory path.
  * @param boolean $throw   Throw an exception on error?
  *
  * @return string The output from the command or null if there is an
  *                error and an exception was not thrown.
  *
  * @throws RuntimeException If there is a problem running the command.
  */
 private function runCommand($command, $dir, $throw = true)
 {
     $process = new Process($command, $dir);
     if (0 === $process->run()) {
         return trim($process->getOutput()) ?: null;
     }
     if ($throw) {
         throw new RuntimeException(sprintf("Git repository error:\n\nOutput:\n%s\n\nError:%s", $process->getOutput() ?: '(none)', $process->getErrorOutput() ?: '(none)'));
     }
     return null;
 }
 /**
  * Perform a test with a given parameter
  *
  * @param TestableSubjectInterface $subject
  *
  * @return float|bool
  */
 public function perform(TestableSubjectInterface $subject)
 {
     $process = new Process(base_path('/resources/speedtest-cli --server ' . $subject->getTesterParameter()));
     $process->setTimeout($this->timeout)->run();
     if ($process->isSuccessful() && strpos($process->getOutput(), $this->pattern) !== false) {
         // Extract speed result from the command output
         $speed = substr($process->getOutput(), strpos($process->getOutput(), $this->pattern) + mb_strlen($this->pattern));
         return floatval(substr($speed, 0, strpos($speed, ' ')));
     } else {
         return false;
     }
 }
示例#12
0
 public function testBuildPhar()
 {
     $fs = new Filesystem();
     $fs->remove(dirname(self::$pharPath));
     $this->ensureDirectoryExists(dirname(self::$pharPath));
     chdir(dirname(self::$pharPath));
     $proc = new Process('php ' . escapeshellarg(__DIR__ . '/../../bin/compile'), dirname(self::$pharPath));
     $exitcode = $proc->run();
     if ($exitcode !== 0 || trim($proc->getOutput())) {
         $this->fail($proc->getOutput());
     }
     $this->assertTrue(file_exists(self::$pharPath));
 }
 /**
  * {@inheritDoc}
  *
  * Starts the connection
  */
 public function _reconfigure($config = array())
 {
     parent::_reconfigure($config);
     if (!isset($this->config['username'])) {
         throw new \Exception("Sauce Connect Extension requires a username.");
     }
     if (!isset($this->config['accesskey'])) {
         throw new \Exception("Sauce Connect Extension requires a accesskey.");
     }
     $connect = __DIR__ . '/../../../bin/sauce_connect';
     if (!file_exists($connect)) {
         $connect = __DIR__ . '/../../../../bin/sauce_connect';
     }
     if (!file_exists($connect)) {
         throw new \Exception("Couldnt find the bin directory... Make sure its in ./bin or ./vendor/bin/");
     }
     $processBuilder = new ProcessBuilder([$connect]);
     $processBuilder->addEnvironmentVariables(['SAUCE_USERNAME' => $this->config['username'], 'SAUCE_ACCESS_KEY' => $this->config['accesskey']]);
     $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 60;
     $this->process = $processBuilder->getProcess();
     $this->process->setTimeout(0);
     $this->process->start(function ($type, $buffer) {
         $buffer = explode("\n", $buffer);
         foreach ($buffer as $line) {
             if (strpos($line, 'Press any key to see more output') === false) {
                 file_put_contents(codecept_output_dir() . 'sauce_connect.log', $line . "\n", FILE_APPEND);
             }
         }
     });
     $timer = 0;
     $connected = false;
     $this->writeln(["", "----------------------------------------------------------------------------", "Attempting to connect to SauceLabs. Waiting {$timeout} seconds."]);
     while ($this->process->isRunning() && $timer < $timeout) {
         $output = $this->process->getOutput();
         if (strpos($output, 'Connected! You may start your tests.') !== false) {
             $connected = true;
             break;
         }
         sleep(1);
         $timer++;
         if ($timer % 5 === 0) {
             $this->write('.');
         }
     }
     if (false === $connected) {
         $this->process->stop();
         throw new \Exception(sprintf("Could not start tunnel. Check %ssauce_connect.log for more information.", codecept_output_dir()));
     }
     $this->writeln(["", "Connected to SauceLabs", "----------------------------------------------------------------------------", ""]);
 }
示例#14
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     parent::prepareView($view);
     if (!isset($this->process)) {
         return;
     }
     if ($this->getRequest()->isMutation()) {
         if ($this->process->getExitCode() === 0) {
             $view->getCommandList()->shutdown($view->getModuleUrl() . '?wait=0', $this->parameters['Action'], array($view->translate('shutdown_' . $this->parameters['Action']), $view->translate('test')));
         } else {
             $view->getCommandList('/Notification')->showMessage("error " . $this->process->getOutput(), \Nethgui\Module\Notification\AbstractNotification::NOTIFY_ERROR);
         }
     }
 }
 /**
  * @param  string $bin
  * @param  array  $args
  * @return string
  */
 public function run($bin, $args)
 {
     if (!is_file($bin)) {
         throw new \InvalidArgumentException(sprintf('Binary %s not found', $bin));
     }
     $process = new Process(sprintf('"%s" %s', $bin, escapeshellcmd($this->arrayToArgsString($args))));
     $process->run();
     if (!$process->isSuccessful()) {
         $this->logger->critical($process->getErrorOutput());
         throw new \RuntimeException($process->getErrorOutput());
     }
     $this->logger->debug(sprintf('SIPS Request output: %s', $process->getOutput()));
     return $process->getOutput();
 }
示例#16
0
 /**
  * Execute command
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return null|integer null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $queueDb = $this->getQueueDatabase();
     $logger = $this->getLogger();
     // Load job
     $jobId = $input->getArgument(self::ARG_ID);
     $job = $queueDb->getJob($jobId);
     $jobCmd = $job->getCommand();
     if (!in_array($job->getStatus(), array(QueueModel::STATUS_WAITING, QueueModel::STATUS_STARTING))) {
         $logContext = array('ID' => $jobId, 'status' => $job->getStatus(), 'cmd' => $job->getCommand());
         $logger->warning('Running job, that already ran', $logContext);
     }
     // Mark job running
     $queueDb->markJobRunning($jobId, getmypid());
     // Log status
     $logger->notice(sprintf('Started Job "%s" (ID %d)', $jobCmd, $jobId));
     // Send a short signal to the parent, so main worker can push us into the background and continue looking for free slots.
     $output->writeln('Marked job running');
     // Prepare command to run
     $consolePath = $this->getContainer()->getParameter('kuborgh_queue.console_path');
     $cmd = sprintf('php %s %s', $consolePath, $jobCmd);
     $process = new Process($cmd);
     try {
         $process->setTimeout(null);
         $process->run();
     } catch (\Exception $exc) {
         // The command failed. Log full output
         $msg = sprintf("Job \"%s\" (ID %d) failed with exception: %s\n%s\n%s", $jobCmd, $jobId, $exc->getMessage(), $process->getErrorOutput(), $process->getOutput());
         $this->getLogger()->error($msg);
         $queueDb->markJobFailed($jobId);
         return -1;
     }
     $logger->notice(sprintf('Job Ended "%s" (ID %d)', $jobCmd, $jobId));
     // Mark job according to the exit code
     $exitCode = $process->getExitCode();
     if (!$exitCode) {
         $logger->notice(sprintf('Finished Job "%s" (ID %d)', $jobCmd, $jobId));
         // log output
         $ctx = array('Output' => $process->getOutput());
         $logger->debug(sprintf('Output of Job "%s" (ID %d)', $jobCmd, $jobId), $ctx);
         $queueDb->markJobDone($jobId);
     } else {
         // log output + error output
         $ctx = array('Output' => $process->getOutput(), 'Error' => $process->getErrorOutput());
         $logger->warning(sprintf('Job Failed "%s" (ID %d)', $jobCmd, $jobId), $ctx);
         $queueDb->markJobFailed($jobId);
     }
     return $exitCode;
 }
示例#17
0
 public function execute()
 {
     $logger = $this->getRunConfig()->getLogger();
     $this->process = new Process($this->command);
     $logger->info('Start command:' . $this->command);
     $this->process->setTimeout($this->timeout);
     $this->process->setWorkingDirectory($this->getRunConfig()->getRepositoryDirectory());
     $this->process->run();
     $output = trim($this->process->getOutput());
     $logger->info($output);
     if (!$this->process->isSuccessful()) {
         $logger->emergency($this->process->getErrorOutput());
         throw new \RuntimeException('Command not successful:' . $this->command);
     }
 }
示例#18
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Defining crontab task...</info>');
     $output->writeln('<info>Please enter the frequency of data aggregating</info> <comment>(frequency must be equal "pinba_stats_history" of the pinba engine config)</comment>.');
     $dialog = $this->getHelperSet()->get('dialog');
     $frequency = $dialog->askAndValidate($output, 'Frequency (in minutes, default "15"): ', function ($answer) {
         if (intval($answer) <= 0) {
             throw new \RunTimeException('You must enter positive integer value');
         }
         return $answer;
     }, false, '15');
     $process = new Process('crontab -l');
     $process->setTimeout(20);
     $process->run();
     $crontabString = $process->isSuccessful() ? $process->getOutput() : '';
     $path = realpath(__DIR__ . '/../../../console');
     $command = '*/' . $frequency . ' * * * * ' . $path . ' aggregate';
     if (strpos($crontabString, $command) === false) {
         $crontabString .= "\n" . $command . "\n";
     }
     $file = tempnam(sys_get_temp_dir(), 'ipm');
     file_put_contents($file, $crontabString);
     $process = new Process('crontab ' . $file);
     $process->setTimeout(20);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $output->writeln('<info>Crontab task are defined successfully</info>');
     $output->writeln('<info>Please set parameter "aggregation_period" to value "PT' . $frequency . 'M" in config/parameters.yml</info>');
 }
示例#19
0
文件: Compiler.php 项目: robo47/Silex
 /**
  * Compiles the Silex source code into one single Phar file.
  *
  * @param string $pharFile Name of the output Phar file
  */
 public function compile($pharFile = 'silex.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $process = new Process('git log --pretty="%h %ci" -n1 HEAD');
     if ($process->run() > 0) {
         throw new \RuntimeException('The git binary cannot be found.');
     }
     $this->version = trim($process->getOutput());
     $phar = new \Phar($pharFile, 0, 'silex.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..')->in(__DIR__ . '/../../vendor/pimple/pimple/lib')->in(__DIR__ . '/../../vendor/symfony/class-loader/Symfony/Component/ClassLoader')->in(__DIR__ . '/../../vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher')->in(__DIR__ . '/../../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation')->in(__DIR__ . '/../../vendor/symfony/http-kernel/Symfony/Component/HttpKernel')->in(__DIR__ . '/../../vendor/symfony/routing/Symfony/Component/Routing')->in(__DIR__ . '/../../vendor/symfony/browser-kit/Symfony/Component/BrowserKit')->in(__DIR__ . '/../../vendor/symfony/css-selector/Symfony/Component/CssSelector')->in(__DIR__ . '/../../vendor/symfony/dom-crawler/Symfony/Component/DomCrawler');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php'));
     // Stubs
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     // $phar->compressFiles(\Phar::GZ);
     unset($phar);
 }
示例#20
0
 public function start()
 {
     if ($this->isRunning()) {
         // Do not allow starting a new agent if there is one already running.
         return false;
     }
     $agent = new Process('ssh-agent -s');
     $agent->run();
     if (!$agent->isSuccessful()) {
         return false;
     }
     // Parse the output for socket and pid
     preg_match_all('/\\s*(.*?)=(.*?);/', $agent->getOutput(), $matches, PREG_SET_ORDER);
     foreach ($matches as $group) {
         switch ($group[1]) {
             case 'SSH_AUTH_SOCK':
                 $this->socket = $group[2];
                 break;
             case 'SSH_AGENT_PID':
                 $this->pid = (int) $group[2];
                 break;
         }
     }
     return true;
 }
示例#21
0
文件: Exec.php 项目: stefanhuber/Robo
 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("Running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             print $buffer;
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
示例#22
0
 public function __construct(\Symfony\Component\Process\Process $process)
 {
     $this->process = $process;
     $code = 0;
     $message = '';
     // Not all of the ansible errors have output in stderr. Therefore, if
     // stderr is empty we will use the stdout output instead to get clues
     // on what the actual error was.
     $error = $process->getErrorOutput();
     if (is_null($error)) {
         $error = $process->getOutput();
     }
     // Figure out the specific error that occured
     if (false !== strpos($error, 'the playbook') && false !== strpos($error, 'could not be found')) {
         $code = self::NOT_FOUND;
         $message = self::NOT_FOUND_MSG;
     } else {
         if (false !== strpos($error, 'Syntax Error while loading YAML script')) {
             $code = self::SYNTAX_ERROR;
             $message = self::SYNTAX_ERROR_MSG;
         } else {
             if (false !== strpos($error, 'One or more undefined variables')) {
                 $code = self::UNDEFINED_VARIABLE;
                 $message = self::UNDEFINED_VARIABLE_MSG;
             } else {
                 $code = self::GENERAL_ERROR;
                 $message = self::GENERAL_ERROR_MSG;
             }
         }
     }
     parent::__construct($message, $code);
 }
 /**
  * Compiles composer into a single phar file
  *
  * @throws \RuntimeException
  */
 public function compile()
 {
     $pharFile = 'refactor.phar';
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $process = new Process('git log --pretty="%H" -n1 HEAD', $this->directory);
     if ($process->run() != 0) {
         throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.');
     }
     $this->version = trim($process->getOutput());
     $process = new Process('git describe --tags HEAD');
     if ($process->run() == 0) {
         $this->version = trim($process->getOutput());
     }
     $phar = new \Phar($pharFile, 0, 'refactor.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in($this->directory . '/src/main');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->exclude('test')->exclude('features')->in($this->directory . '/vendor/');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $this->addRefactorBin($phar);
     // Stubs
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     unset($phar);
 }
示例#24
0
文件: Server.php 项目: tillk/vufind
 /**
  * Starts the server process
  *
  * @param Process $process A process object
  *
  * @throws \RuntimeException
  */
 public function start(Process $process = null)
 {
     // Check if the server script exists at given path
     if (false === $this->serverPath || false === is_file($this->serverPath)) {
         throw new \RuntimeException(sprintf("Could not find server script at path '%s'", $this->serverPath));
     }
     // Create process object if neccessary
     if (null === $process) {
         $processBuilder = new ProcessBuilder(array($this->nodeBin, $this->serverPath));
         $process = $processBuilder->getProcess();
     }
     $this->process = $process;
     // Start server process
     $this->process->start();
     $this->connection = null;
     // Wait for the server to start up
     $time = 0;
     $successString = sprintf("server started on %s:%s", $this->host, $this->port);
     while ($this->process->isRunning() && $time < $this->threshold) {
         if ($successString == trim($this->process->getOutput())) {
             $this->connection = new Connection($this->host, $this->port);
             break;
         }
         usleep(1000);
         $time += 1000;
     }
     // Make sure the server is ready or throw an exception otherwise
     $this->checkAvailability();
 }
示例#25
0
 /**
  * @dataProvider getTestFiles
  * @depends testBuildPhar
  */
 public function testIntegration(\SplFileInfo $testFile)
 {
     $testData = $this->parseTestFile($testFile);
     $this->oldenv = getenv('COMPOSER_HOME');
     $_SERVER['COMPOSER_HOME'] = $this->testDir . 'home';
     putenv('COMPOSER_HOME=' . $_SERVER['COMPOSER_HOME']);
     $cmd = 'php ' . escapeshellarg(self::$pharPath) . ' --no-ansi ' . $testData['RUN'];
     $proc = new Process($cmd, __DIR__ . '/Fixtures/functional', null, null, 300);
     $exitcode = $proc->run();
     if (isset($testData['EXPECT'])) {
         $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-ERROR'])) {
         $this->assertEquals($testData['EXPECT-ERROR'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-ERROR-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-ERROR-REGEX'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-EXIT-CODE'])) {
         $this->assertSame($testData['EXPECT-EXIT-CODE'], $exitcode);
     }
 }
示例#26
0
 /**
  * Compiles composer into a single phar file
  *
  * @throws \RuntimeException
  * @param string $pharFile The full path to the file to create
  */
 public function compile($pharFile = 'composer.phar')
 {
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $process = new Process('git log --pretty="%h" -n1 HEAD');
     if ($process->run() != 0) {
         throw new \RuntimeException('The git binary cannot be found.');
     }
     $this->version = trim($process->getOutput());
     $phar = new \Phar($pharFile, 0, 'composer.phar');
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $finder = new Finder();
     $finder->files()->ignoreVCS(true)->name('*.php')->in(__DIR__ . '/../../vendor/symfony/');
     foreach ($finder as $file) {
         $this->addFile($phar, $file);
     }
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php'));
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php'));
     $this->addComposerBin($phar);
     // Stubs
     $phar->setStub($this->getStub());
     $phar->stopBuffering();
     // disabled for interoperability with systems without gzip ext
     // $phar->compressFiles(\Phar::GZ);
     $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);
     unset($phar);
 }
 /**
  * Runs the given string as a command and returns the resulting output.
  * The CWD is set to the root project directory to simplify command paths.
  *
  * @param string $command
  *
  * @return string
  *
  * @throws ProcessFailedException in case the command execution is not successful
  */
 private function runCommand($command, $workingDirectory = null)
 {
     $process = new Process($command);
     $process->setWorkingDirectory($workingDirectory ?: $this->rootDir);
     $process->mustRun();
     return $process->getOutput();
 }
示例#28
0
文件: Exec.php 项目: sliver/Robo
 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (!$this->background and !$this->isPrinted) {
         $this->process->run();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     if (!$this->background and $this->isPrinted) {
         $this->process->run(function ($type, $buffer) {
             Process::ERR === $type ? print 'ER» ' . $buffer : (print '» ' . $buffer);
         });
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
示例#29
0
 /**
  * Check if linting process was successful and raise LintingException if not.
  *
  * @param Process $process
  */
 private function checkProcess(Process $process)
 {
     if (!$process->isSuccessful()) {
         // on some systems stderr is used, but on others, it's not
         throw new LintingException($process->getErrorOutput() ?: $process->getOutput(), $process->getExitCode());
     }
 }
示例#30
0
 /**
  *@group cmd
  */
 public function testPhpdocIsInstalled()
 {
     $process = new Process('phpdoc --version');
     $process->run();
     $output = $process->getOutput();
     $this->assertContains("phpDocumentor version", $output);
 }