You are here

public function ProcessHelperTest::provideCommandsAndOutput in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Tests/Helper/ProcessHelperTest.php \Symfony\Component\Console\Tests\Helper\ProcessHelperTest::provideCommandsAndOutput()

File

vendor/symfony/console/Tests/Helper/ProcessHelperTest.php, line 47

Class

ProcessHelperTest

Namespace

Symfony\Component\Console\Tests\Helper

Code

public function provideCommandsAndOutput() {
  $successOutputVerbose = <<<EOT
  RUN  php -r "echo 42;"
  RES  Command ran successfully

EOT;
  $successOutputDebug = <<<EOT
  RUN  php -r "echo 42;"
  OUT  42
  RES  Command ran successfully

EOT;
  $successOutputDebugWithTags = <<<EOT
  RUN  php -r "echo '<info>42</info>';"
  OUT  <info>42</info>
  RES  Command ran successfully

EOT;
  $successOutputProcessDebug = <<<EOT
  RUN  'php' '-r' 'echo 42;'
  OUT  42
  RES  Command ran successfully

EOT;
  $syntaxErrorOutputVerbose = <<<EOT
  RUN  php -r "fwrite(STDERR, 'error message');usleep(50000);fwrite(STDOUT, 'out message');exit(252);"
  RES  252 Command did not run successfully

EOT;
  $syntaxErrorOutputDebug = <<<EOT
  RUN  php -r "fwrite(STDERR, 'error message');usleep(500000);fwrite(STDOUT, 'out message');exit(252);"
  ERR  error message
  OUT  out message
  RES  252 Command did not run successfully

EOT;
  $errorMessage = 'An error occurred';
  if ('\\' === DIRECTORY_SEPARATOR) {
    $successOutputProcessDebug = str_replace("'", '"', $successOutputProcessDebug);
  }
  return array(
    array(
      '',
      'php -r "echo 42;"',
      StreamOutput::VERBOSITY_VERBOSE,
      null,
    ),
    array(
      $successOutputVerbose,
      'php -r "echo 42;"',
      StreamOutput::VERBOSITY_VERY_VERBOSE,
      null,
    ),
    array(
      $successOutputDebug,
      'php -r "echo 42;"',
      StreamOutput::VERBOSITY_DEBUG,
      null,
    ),
    array(
      $successOutputDebugWithTags,
      'php -r "echo \'<info>42</info>\';"',
      StreamOutput::VERBOSITY_DEBUG,
      null,
    ),
    array(
      '',
      'php -r "syntax error"',
      StreamOutput::VERBOSITY_VERBOSE,
      null,
    ),
    array(
      $syntaxErrorOutputVerbose,
      'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"',
      StreamOutput::VERBOSITY_VERY_VERBOSE,
      null,
    ),
    array(
      $syntaxErrorOutputDebug,
      'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"',
      StreamOutput::VERBOSITY_DEBUG,
      null,
    ),
    array(
      $errorMessage . PHP_EOL,
      'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"',
      StreamOutput::VERBOSITY_VERBOSE,
      $errorMessage,
    ),
    array(
      $syntaxErrorOutputVerbose . $errorMessage . PHP_EOL,
      'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"',
      StreamOutput::VERBOSITY_VERY_VERBOSE,
      $errorMessage,
    ),
    array(
      $syntaxErrorOutputDebug . $errorMessage . PHP_EOL,
      'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"',
      StreamOutput::VERBOSITY_DEBUG,
      $errorMessage,
    ),
    array(
      $successOutputProcessDebug,
      array(
        'php',
        '-r',
        'echo 42;',
      ),
      StreamOutput::VERBOSITY_DEBUG,
      null,
    ),
    array(
      $successOutputDebug,
      new Process('php -r "echo 42;"'),
      StreamOutput::VERBOSITY_DEBUG,
      null,
    ),
  );
}