summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Tests/Helper/ProcessHelperTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-10-25 16:22:10 -0700
committerFrederic Guillot <fred@kanboard.net>2017-10-25 16:22:10 -0700
commit9e2b2a32fd0e967ad3184e9a5d091a29953acb91 (patch)
tree00822e24aa1110c73ca455a8d096ef296c008cbc /vendor/symfony/console/Tests/Helper/ProcessHelperTest.php
parentc507c5416251c505cb3e088a03c6664bed73c812 (diff)
Include composer dependencies in repo
Diffstat (limited to 'vendor/symfony/console/Tests/Helper/ProcessHelperTest.php')
-rw-r--r--vendor/symfony/console/Tests/Helper/ProcessHelperTest.php117
1 files changed, 117 insertions, 0 deletions
diff --git a/vendor/symfony/console/Tests/Helper/ProcessHelperTest.php b/vendor/symfony/console/Tests/Helper/ProcessHelperTest.php
new file mode 100644
index 00000000..a51fb435
--- /dev/null
+++ b/vendor/symfony/console/Tests/Helper/ProcessHelperTest.php
@@ -0,0 +1,117 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Console\Tests\Helper;
+
+use Symfony\Component\Console\Helper\DebugFormatterHelper;
+use Symfony\Component\Console\Helper\HelperSet;
+use Symfony\Component\Console\Output\StreamOutput;
+use Symfony\Component\Console\Helper\ProcessHelper;
+use Symfony\Component\Process\Process;
+
+class ProcessHelperTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider provideCommandsAndOutput
+ */
+ public function testVariousProcessRuns($expected, $cmd, $verbosity, $error)
+ {
+ $helper = new ProcessHelper();
+ $helper->setHelperSet(new HelperSet(array(new DebugFormatterHelper())));
+ $output = $this->getOutputStream($verbosity);
+ $helper->run($output, $cmd, $error);
+ $this->assertEquals($expected, $this->getOutput($output));
+ }
+
+ 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);
+ }
+
+ 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),
+ );
+ }
+
+ private function getOutputStream($verbosity)
+ {
+ return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, false);
+ }
+
+ private function getOutput(StreamOutput $output)
+ {
+ rewind($output->getStream());
+
+ return stream_get_contents($output->getStream());
+ }
+}