2011-05-09 21:40:18 +01:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2012-03-28 14:43:52 +01:00
|
|
|
namespace Symfony\Component\Process\Tests;
|
2011-05-09 21:40:18 +01:00
|
|
|
|
2014-04-21 22:11:42 +01:00
|
|
|
use Symfony\Component\Process\Exception\LogicException;
|
2015-06-30 17:10:16 +01:00
|
|
|
use Symfony\Component\Process\Exception\ProcessTimedOutException;
|
|
|
|
use Symfony\Component\Process\Exception\RuntimeException;
|
2015-06-30 07:51:58 +01:00
|
|
|
use Symfony\Component\Process\PhpExecutableFinder;
|
2014-04-22 22:51:46 +01:00
|
|
|
use Symfony\Component\Process\Pipes\PipesInterface;
|
2012-10-27 14:48:18 +01:00
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
/**
|
|
|
|
* @author Robert Schönthal <seroscho@googlemail.com>
|
|
|
|
*/
|
2012-09-09 15:38:21 +01:00
|
|
|
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
2011-05-09 21:40:18 +01:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
protected static $phpBin;
|
|
|
|
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
$phpBin = new PhpExecutableFinder();
|
|
|
|
self::$phpBin = $phpBin->find();
|
|
|
|
}
|
|
|
|
|
2013-10-24 03:56:37 +01:00
|
|
|
public function testThatProcessDoesNotThrowWarningDuringRun()
|
|
|
|
{
|
|
|
|
@trigger_error('Test Error', E_USER_NOTICE);
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin." -r 'sleep(3)'");
|
2013-10-24 03:56:37 +01:00
|
|
|
$process->run();
|
|
|
|
$actualError = error_get_last();
|
|
|
|
$this->assertEquals('Test Error', $actualError['message']);
|
|
|
|
$this->assertEquals(E_USER_NOTICE, $actualError['type']);
|
|
|
|
}
|
|
|
|
|
2012-07-10 14:21:23 +01:00
|
|
|
/**
|
2013-01-05 17:52:40 +00:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
|
2012-07-10 14:21:23 +01:00
|
|
|
*/
|
|
|
|
public function testNegativeTimeoutFromConstructor()
|
|
|
|
{
|
2012-09-09 15:38:21 +01:00
|
|
|
$this->getProcess('', null, null, null, -1);
|
2012-07-10 14:21:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-05 17:52:40 +00:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
|
2012-07-10 14:21:23 +01:00
|
|
|
*/
|
|
|
|
public function testNegativeTimeoutFromSetter()
|
|
|
|
{
|
2012-09-09 15:38:21 +01:00
|
|
|
$p = $this->getProcess('');
|
2012-07-10 14:21:23 +01:00
|
|
|
$p->setTimeout(-1);
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:33:52 +00:00
|
|
|
public function testFloatAndNullTimeout()
|
2012-07-11 13:21:05 +01:00
|
|
|
{
|
2012-09-09 15:38:21 +01:00
|
|
|
$p = $this->getProcess('');
|
2013-11-08 00:33:52 +00:00
|
|
|
|
2012-07-11 13:21:05 +01:00
|
|
|
$p->setTimeout(10);
|
2013-11-08 00:33:52 +00:00
|
|
|
$this->assertSame(10.0, $p->getTimeout());
|
|
|
|
|
2012-07-11 13:21:05 +01:00
|
|
|
$p->setTimeout(null);
|
2013-11-08 00:33:52 +00:00
|
|
|
$this->assertNull($p->getTimeout());
|
2012-07-11 13:21:05 +01:00
|
|
|
|
2013-11-08 00:33:52 +00:00
|
|
|
$p->setTimeout(0.0);
|
2012-07-11 13:21:05 +01:00
|
|
|
$this->assertNull($p->getTimeout());
|
|
|
|
}
|
|
|
|
|
2013-04-06 18:59:02 +01:00
|
|
|
public function testStopWithTimeoutIsActuallyWorking()
|
|
|
|
{
|
2013-06-13 20:00:58 +01:00
|
|
|
$this->verifyPosixIsEnabled();
|
2013-04-06 18:59:02 +01:00
|
|
|
|
|
|
|
// exec is mandatory here since we send a signal to the process
|
|
|
|
// see https://github.com/symfony/symfony/issues/5030 about prepending
|
|
|
|
// command with exec
|
|
|
|
$p = $this->getProcess('exec php '.__DIR__.'/NonStopableProcess.php 3');
|
|
|
|
$p->start();
|
|
|
|
usleep(100000);
|
|
|
|
$start = microtime(true);
|
2012-09-09 15:56:43 +01:00
|
|
|
$p->stop(1.1, SIGKILL);
|
2013-04-06 18:59:02 +01:00
|
|
|
while ($p->isRunning()) {
|
|
|
|
usleep(1000);
|
|
|
|
}
|
|
|
|
$duration = microtime(true) - $start;
|
|
|
|
|
2014-11-03 19:48:45 +00:00
|
|
|
$this->assertLessThan(4, $duration);
|
2013-04-06 18:59:02 +01:00
|
|
|
}
|
2012-07-11 13:21:05 +01:00
|
|
|
|
2014-01-28 16:56:56 +00:00
|
|
|
public function testAllOutputIsActuallyReadOnTermination()
|
|
|
|
{
|
|
|
|
// this code will result in a maximum of 2 reads of 8192 bytes by calling
|
|
|
|
// start() and isRunning(). by the time getOutput() is called the process
|
|
|
|
// has terminated so the internal pipes array is already empty. normally
|
|
|
|
// the call to start() will not read any data as the process will not have
|
|
|
|
// generated output, but this is non-deterministic so we must count it as
|
2014-04-22 22:51:46 +01:00
|
|
|
// a possibility. therefore we need 2 * PipesInterface::CHUNK_SIZE plus
|
2014-03-14 16:03:41 +00:00
|
|
|
// another byte which will never be read.
|
2014-04-22 22:51:46 +01:00
|
|
|
$expectedOutputSize = PipesInterface::CHUNK_SIZE * 2 + 2;
|
2014-01-28 16:56:56 +00:00
|
|
|
|
|
|
|
$code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
2014-01-28 16:56:56 +00:00
|
|
|
|
|
|
|
$p->start();
|
2014-03-14 16:03:41 +00:00
|
|
|
// Let's wait enough time for process to finish...
|
|
|
|
// Here we don't call Process::run or Process::wait to avoid any read of pipes
|
|
|
|
usleep(500000);
|
2014-01-28 16:56:56 +00:00
|
|
|
|
|
|
|
if ($p->isRunning()) {
|
2014-03-14 16:03:41 +00:00
|
|
|
$this->markTestSkipped('Process execution did not complete in the required time frame');
|
2014-01-28 16:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$o = $p->getOutput();
|
|
|
|
|
|
|
|
$this->assertEquals($expectedOutputSize, strlen($o));
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:56:09 +01:00
|
|
|
public function testCallbacksAreExecutedWithStart()
|
|
|
|
{
|
|
|
|
$data = '';
|
|
|
|
|
2013-09-02 09:23:35 +01:00
|
|
|
$process = $this->getProcess('echo foo && php -r "sleep(1);" && echo foo');
|
2013-08-13 16:56:09 +01:00
|
|
|
$process->start(function ($type, $buffer) use (&$data) {
|
|
|
|
$data .= $buffer;
|
|
|
|
});
|
|
|
|
|
|
|
|
while ($process->isRunning()) {
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
|
2013-09-02 09:23:35 +01:00
|
|
|
$this->assertEquals(2, preg_match_all('/foo/', $data, $matches));
|
2013-08-13 16:56:09 +01:00
|
|
|
}
|
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* tests results from sub processes.
|
2011-06-08 18:56:59 +01:00
|
|
|
*
|
2011-06-22 20:47:44 +01:00
|
|
|
* @dataProvider responsesCodeProvider
|
2011-05-09 21:40:18 +01:00
|
|
|
*/
|
2011-05-09 22:21:57 +01:00
|
|
|
public function testProcessResponses($expected, $getter, $code)
|
2011-05-09 21:40:18 +01:00
|
|
|
{
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
2011-05-09 21:40:18 +01:00
|
|
|
$p->run();
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
$this->assertSame($expected, $p->$getter());
|
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-06-22 20:47:44 +01:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* tests results from sub processes.
|
2011-06-22 20:47:44 +01:00
|
|
|
*
|
|
|
|
* @dataProvider pipesCodeProvider
|
|
|
|
*/
|
2013-05-06 10:50:13 +01:00
|
|
|
public function testProcessPipes($code, $size)
|
2011-06-22 20:47:44 +01:00
|
|
|
{
|
2014-09-21 19:53:12 +01:00
|
|
|
$expected = str_repeat(str_repeat('*', 1024), $size).'!';
|
2013-05-06 10:50:13 +01:00
|
|
|
$expectedLength = (1024 * $size) + 1;
|
|
|
|
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
2014-05-17 19:36:38 +01:00
|
|
|
$p->setInput($expected);
|
2011-06-22 20:47:44 +01:00
|
|
|
$p->run();
|
|
|
|
|
2013-05-06 10:50:13 +01:00
|
|
|
$this->assertEquals($expectedLength, strlen($p->getOutput()));
|
|
|
|
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
|
2011-06-22 20:47:44 +01:00
|
|
|
}
|
|
|
|
|
2014-04-22 22:51:46 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider pipesCodeProvider
|
|
|
|
*/
|
|
|
|
public function testSetStreamAsInput($code, $size)
|
|
|
|
{
|
2014-09-22 12:59:59 +01:00
|
|
|
$expected = str_repeat(str_repeat('*', 1024), $size).'!';
|
2014-04-22 22:51:46 +01:00
|
|
|
$expectedLength = (1024 * $size) + 1;
|
|
|
|
|
|
|
|
$stream = fopen('php://temporary', 'w+');
|
|
|
|
fwrite($stream, $expected);
|
|
|
|
rewind($stream);
|
|
|
|
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
|
2014-04-22 22:51:46 +01:00
|
|
|
$p->setInput($stream);
|
|
|
|
$p->run();
|
|
|
|
|
|
|
|
fclose($stream);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedLength, strlen($p->getOutput()));
|
|
|
|
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
|
|
|
|
}
|
|
|
|
|
2014-05-17 19:36:38 +01:00
|
|
|
public function testSetInputWhileRunningThrowsAnException()
|
2014-04-21 22:11:42 +01:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2014-04-21 22:11:42 +01:00
|
|
|
$process->start();
|
|
|
|
try {
|
2014-05-17 19:36:38 +01:00
|
|
|
$process->setInput('foobar');
|
2014-04-21 22:11:42 +01:00
|
|
|
$process->stop();
|
|
|
|
$this->fail('A LogicException should have been raised.');
|
|
|
|
} catch (LogicException $e) {
|
2014-05-17 19:36:38 +01:00
|
|
|
$this->assertEquals('Input can not be set while the process is running.', $e->getMessage());
|
2014-04-21 22:11:42 +01:00
|
|
|
}
|
|
|
|
$process->stop();
|
|
|
|
}
|
|
|
|
|
2014-05-17 18:27:19 +01:00
|
|
|
/**
|
2014-05-22 21:31:58 +01:00
|
|
|
* @dataProvider provideInvalidInputValues
|
2014-05-17 18:27:19 +01:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
|
2014-04-22 22:51:46 +01:00
|
|
|
* @expectedExceptionMessage Symfony\Component\Process\Process::setInput only accepts strings or stream resources.
|
2014-05-17 18:27:19 +01:00
|
|
|
*/
|
2014-05-22 21:31:58 +01:00
|
|
|
public function testInvalidInput($value)
|
2014-05-17 18:27:19 +01:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2014-05-22 21:31:58 +01:00
|
|
|
$process->setInput($value);
|
2014-05-17 18:27:19 +01:00
|
|
|
}
|
|
|
|
|
2014-05-22 21:31:58 +01:00
|
|
|
public function provideInvalidInputValues()
|
2014-05-17 18:27:19 +01:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(array()),
|
|
|
|
array(new NonStringifiable()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-22 21:31:58 +01:00
|
|
|
* @dataProvider provideInputValues
|
2014-05-17 18:27:19 +01:00
|
|
|
*/
|
2014-05-22 21:31:58 +01:00
|
|
|
public function testValidInput($expected, $value)
|
2014-05-17 18:27:19 +01:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2014-05-22 21:31:58 +01:00
|
|
|
$process->setInput($value);
|
|
|
|
$this->assertSame($expected, $process->getInput());
|
2014-05-17 18:27:19 +01:00
|
|
|
}
|
|
|
|
|
2014-05-22 21:31:58 +01:00
|
|
|
public function provideInputValues()
|
2014-05-17 18:27:19 +01:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(null, null),
|
|
|
|
array('24.5', 24.5),
|
|
|
|
array('input data', 'input data'),
|
2015-02-05 08:19:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideLegacyInputValues
|
2015-03-13 17:49:40 +00:00
|
|
|
* @group legacy
|
2015-02-05 08:19:53 +00:00
|
|
|
*/
|
|
|
|
public function testLegacyValidInput($expected, $value)
|
|
|
|
{
|
2015-07-01 12:25:50 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2015-02-05 08:19:53 +00:00
|
|
|
$process->setInput($value);
|
|
|
|
$this->assertSame($expected, $process->getInput());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideLegacyInputValues()
|
|
|
|
{
|
|
|
|
return array(
|
2014-05-17 18:27:19 +01:00
|
|
|
array('stringifiable', new Stringifiable()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:21:47 +01:00
|
|
|
public function chainedCommandsOutputProvider()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-09-02 09:23:35 +01:00
|
|
|
return array(
|
2014-09-21 19:53:12 +01:00
|
|
|
array("2 \r\n2\r\n", '&&', '2'),
|
2013-09-02 09:23:35 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-25 09:21:47 +01:00
|
|
|
return array(
|
2012-11-19 17:07:58 +00:00
|
|
|
array("1\n1\n", ';', '1'),
|
|
|
|
array("2\n2\n", '&&', '2'),
|
2012-09-25 09:21:47 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider chainedCommandsOutputProvider
|
|
|
|
*/
|
|
|
|
public function testChainedCommandsOutput($expected, $operator, $input)
|
2012-09-22 02:03:15 +01:00
|
|
|
{
|
2012-11-19 17:07:58 +00:00
|
|
|
$process = $this->getProcess(sprintf('echo %s %s echo %s', $input, $operator, $input));
|
2012-09-22 02:03:15 +01:00
|
|
|
$process->run();
|
2012-09-25 09:21:47 +01:00
|
|
|
$this->assertEquals($expected, $process->getOutput());
|
2012-09-22 02:03:15 +01:00
|
|
|
}
|
|
|
|
|
2012-05-24 18:52:29 +01:00
|
|
|
public function testCallbackIsExecutedForOutput()
|
|
|
|
{
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('echo \'foo\';')));
|
2012-05-24 18:52:29 +01:00
|
|
|
|
|
|
|
$called = false;
|
|
|
|
$p->run(function ($type, $buffer) use (&$called) {
|
|
|
|
$called = $buffer === 'foo';
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assertTrue($called, 'The callback should be executed with the output');
|
|
|
|
}
|
|
|
|
|
2012-09-19 01:35:24 +01:00
|
|
|
public function testGetErrorOutput()
|
|
|
|
{
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
|
2012-09-19 01:35:24 +01:00
|
|
|
|
|
|
|
$p->run();
|
2013-04-25 14:23:11 +01:00
|
|
|
$this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches));
|
2012-09-19 01:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIncrementalErrorOutput()
|
|
|
|
{
|
2014-08-05 10:52:34 +01:00
|
|
|
// use a lock file to toggle between writing ("W") and reading ("R") the
|
|
|
|
// error stream
|
|
|
|
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));
|
2012-09-19 01:35:24 +01:00
|
|
|
|
|
|
|
$p->start();
|
2012-10-27 17:54:34 +01:00
|
|
|
while ($p->isRunning()) {
|
2014-08-05 10:52:34 +01:00
|
|
|
if ('R' === file_get_contents($lock)) {
|
|
|
|
$this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getIncrementalErrorOutput(), $matches));
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
}
|
|
|
|
usleep(100);
|
2012-09-19 01:35:24 +01:00
|
|
|
}
|
2014-08-05 10:52:34 +01:00
|
|
|
|
|
|
|
unlink($lock);
|
2012-09-19 01:35:24 +01:00
|
|
|
}
|
|
|
|
|
2013-06-16 10:12:20 +01:00
|
|
|
public function testFlushErrorOutput()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
|
2013-06-16 10:12:20 +01:00
|
|
|
|
|
|
|
$p->run();
|
2013-10-30 12:27:00 +00:00
|
|
|
$p->clearErrorOutput();
|
2013-06-16 10:12:20 +01:00
|
|
|
$this->assertEmpty($p->getErrorOutput());
|
|
|
|
}
|
|
|
|
|
2014-12-31 00:27:17 +00:00
|
|
|
public function testGetEmptyIncrementalErrorOutput()
|
|
|
|
{
|
|
|
|
// use a lock file to toggle between writing ("W") and reading ("R") the
|
|
|
|
// output stream
|
|
|
|
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));
|
2014-12-31 00:27:17 +00:00
|
|
|
|
|
|
|
$p->start();
|
|
|
|
|
|
|
|
$shouldWrite = false;
|
|
|
|
|
|
|
|
while ($p->isRunning()) {
|
|
|
|
if ('R' === file_get_contents($lock)) {
|
|
|
|
if (!$shouldWrite) {
|
|
|
|
$this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getIncrementalOutput(), $matches));
|
|
|
|
$shouldWrite = true;
|
|
|
|
} else {
|
|
|
|
$this->assertSame('', $p->getIncrementalOutput());
|
|
|
|
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
$shouldWrite = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
unlink($lock);
|
|
|
|
}
|
|
|
|
|
2012-09-19 01:35:24 +01:00
|
|
|
public function testGetOutput()
|
|
|
|
{
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }')));
|
2012-09-19 01:35:24 +01:00
|
|
|
|
|
|
|
$p->run();
|
|
|
|
$this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIncrementalOutput()
|
|
|
|
{
|
2014-08-05 10:52:34 +01:00
|
|
|
// use a lock file to toggle between writing ("W") and reading ("R") the
|
|
|
|
// output stream
|
|
|
|
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));
|
2012-09-19 01:35:24 +01:00
|
|
|
|
|
|
|
$p->start();
|
2012-10-27 17:54:34 +01:00
|
|
|
while ($p->isRunning()) {
|
2014-08-05 10:52:34 +01:00
|
|
|
if ('R' === file_get_contents($lock)) {
|
|
|
|
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
}
|
|
|
|
usleep(100);
|
2012-09-19 01:35:24 +01:00
|
|
|
}
|
2014-08-05 10:52:34 +01:00
|
|
|
|
|
|
|
unlink($lock);
|
2012-09-19 01:35:24 +01:00
|
|
|
}
|
|
|
|
|
2013-06-16 10:12:20 +01:00
|
|
|
public function testFlushOutput()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
|
2013-06-16 10:12:20 +01:00
|
|
|
|
|
|
|
$p->run();
|
2013-10-30 12:27:00 +00:00
|
|
|
$p->clearOutput();
|
2013-06-16 10:12:20 +01:00
|
|
|
$this->assertEmpty($p->getOutput());
|
|
|
|
}
|
|
|
|
|
2014-12-31 00:27:17 +00:00
|
|
|
public function testGetEmptyIncrementalOutput()
|
|
|
|
{
|
|
|
|
// use a lock file to toggle between writing ("W") and reading ("R") the
|
|
|
|
// output stream
|
|
|
|
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
|
2015-06-30 17:05:31 +01:00
|
|
|
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));
|
2014-12-31 00:27:17 +00:00
|
|
|
|
|
|
|
$p->start();
|
|
|
|
|
|
|
|
$shouldWrite = false;
|
|
|
|
|
|
|
|
while ($p->isRunning()) {
|
|
|
|
if ('R' === file_get_contents($lock)) {
|
|
|
|
if (!$shouldWrite) {
|
|
|
|
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
|
|
|
|
$shouldWrite = true;
|
|
|
|
} else {
|
|
|
|
$this->assertSame('', $p->getIncrementalOutput());
|
|
|
|
|
|
|
|
file_put_contents($lock, 'W');
|
|
|
|
$shouldWrite = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
unlink($lock);
|
|
|
|
}
|
|
|
|
|
2014-07-12 15:27:05 +01:00
|
|
|
public function testZeroAsOutput()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2014-07-12 15:27:05 +01:00
|
|
|
// see http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line
|
|
|
|
$p = $this->getProcess('echo | set /p dummyName=0');
|
|
|
|
} else {
|
|
|
|
$p = $this->getProcess('printf 0');
|
|
|
|
}
|
|
|
|
|
2014-07-01 14:28:47 +01:00
|
|
|
$p->run();
|
|
|
|
$this->assertSame('0', $p->getOutput());
|
|
|
|
}
|
|
|
|
|
2012-08-30 11:55:38 +01:00
|
|
|
public function testExitCodeCommandFailed()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2012-08-30 11:55:38 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX exit code');
|
|
|
|
}
|
|
|
|
|
|
|
|
// such command run in bash return an exitcode 127
|
2012-09-09 15:38:21 +01:00
|
|
|
$process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
|
2012-08-30 11:55:38 +01:00
|
|
|
$process->run();
|
|
|
|
|
|
|
|
$this->assertGreaterThan(0, $process->getExitCode());
|
|
|
|
}
|
|
|
|
|
2013-04-05 11:35:05 +01:00
|
|
|
public function testTTYCommand()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-04-05 11:35:05 +01:00
|
|
|
$this->markTestSkipped('Windows does have /dev/tty support');
|
|
|
|
}
|
|
|
|
|
2014-03-14 16:09:12 +00:00
|
|
|
$process = $this->getProcess('echo "foo" >> /dev/null && php -r "usleep(100000);"');
|
2014-04-22 21:38:30 +01:00
|
|
|
$process->setTty(true);
|
2014-03-10 16:14:59 +00:00
|
|
|
$process->start();
|
|
|
|
$this->assertTrue($process->isRunning());
|
|
|
|
$process->wait();
|
2013-04-05 11:35:05 +01:00
|
|
|
|
|
|
|
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
|
|
|
|
}
|
|
|
|
|
2014-03-10 16:14:59 +00:00
|
|
|
public function testTTYCommandExitCode()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2014-03-10 16:14:59 +00:00
|
|
|
$this->markTestSkipped('Windows does have /dev/tty support');
|
|
|
|
}
|
|
|
|
|
2013-04-05 11:35:05 +01:00
|
|
|
$process = $this->getProcess('echo "foo" >> /dev/null');
|
2014-04-22 21:38:30 +01:00
|
|
|
$process->setTty(true);
|
2013-04-05 11:35:05 +01:00
|
|
|
$process->run();
|
|
|
|
|
2014-03-10 16:14:59 +00:00
|
|
|
$this->assertTrue($process->isSuccessful());
|
|
|
|
}
|
|
|
|
|
2014-04-22 21:38:30 +01:00
|
|
|
public function testTTYInWindowsEnvironment()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' !== DIRECTORY_SEPARATOR) {
|
2014-04-22 21:38:30 +01:00
|
|
|
$this->markTestSkipped('This test is for Windows platform only');
|
|
|
|
}
|
|
|
|
|
|
|
|
$process = $this->getProcess('echo "foo" >> /dev/null');
|
|
|
|
$process->setTty(false);
|
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'TTY mode is not supported on Windows platform.');
|
|
|
|
$process->setTty(true);
|
|
|
|
}
|
|
|
|
|
2014-03-18 15:17:31 +00:00
|
|
|
public function testExitCodeTextIsNullWhenExitCodeIsNull()
|
|
|
|
{
|
|
|
|
$process = $this->getProcess('');
|
|
|
|
$this->assertNull($process->getExitCodeText());
|
2013-04-05 11:35:05 +01:00
|
|
|
}
|
|
|
|
|
2013-08-03 08:10:03 +01:00
|
|
|
public function testPTYCommand()
|
|
|
|
{
|
2014-02-03 08:11:05 +00:00
|
|
|
if (!Process::isPtySupported()) {
|
2013-08-03 08:57:35 +01:00
|
|
|
$this->markTestSkipped('PTY is not supported on this operating system.');
|
2013-08-03 08:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$process = $this->getProcess('echo "foo"');
|
|
|
|
$process->setPty(true);
|
|
|
|
$process->run();
|
|
|
|
|
|
|
|
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
|
|
|
|
$this->assertEquals("foo\r\n", $process->getOutput());
|
|
|
|
}
|
|
|
|
|
2013-08-03 08:24:32 +01:00
|
|
|
public function testMustRun()
|
|
|
|
{
|
2014-03-31 08:31:57 +01:00
|
|
|
$process = $this->getProcess('echo foo');
|
2013-08-03 08:24:32 +01:00
|
|
|
|
|
|
|
$this->assertSame($process, $process->mustRun());
|
2014-03-31 08:31:57 +01:00
|
|
|
$this->assertEquals("foo".PHP_EOL, $process->getOutput());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSuccessfulMustRunHasCorrectExitCode()
|
|
|
|
{
|
|
|
|
$process = $this->getProcess('echo foo')->mustRun();
|
2013-08-03 08:24:32 +01:00
|
|
|
$this->assertEquals(0, $process->getExitCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-28 17:24:17 +01:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
|
2013-08-03 08:24:32 +01:00
|
|
|
*/
|
|
|
|
public function testMustRunThrowsException()
|
|
|
|
{
|
|
|
|
$process = $this->getProcess('exit 1');
|
|
|
|
$process->mustRun();
|
|
|
|
}
|
|
|
|
|
2012-02-13 06:31:37 +00:00
|
|
|
public function testExitCodeText()
|
|
|
|
{
|
2012-09-09 15:38:21 +01:00
|
|
|
$process = $this->getProcess('');
|
2012-02-13 06:31:37 +00:00
|
|
|
$r = new \ReflectionObject($process);
|
|
|
|
$p = $r->getProperty('exitcode');
|
|
|
|
$p->setAccessible(true);
|
|
|
|
|
|
|
|
$p->setValue($process, 2);
|
|
|
|
$this->assertEquals('Misuse of shell builtins', $process->getExitCodeText());
|
|
|
|
}
|
|
|
|
|
2012-03-21 16:58:02 +00:00
|
|
|
public function testStartIsNonBlocking()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2012-03-21 16:58:02 +00:00
|
|
|
$start = microtime(true);
|
|
|
|
$process->start();
|
|
|
|
$end = microtime(true);
|
2014-03-11 16:00:25 +00:00
|
|
|
$this->assertLessThan(0.2, $end-$start);
|
|
|
|
$process->wait();
|
2012-03-21 16:58:02 +00:00
|
|
|
}
|
|
|
|
|
2012-03-23 11:59:10 +00:00
|
|
|
public function testUpdateStatus()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->run();
|
2012-03-23 11:59:10 +00:00
|
|
|
$this->assertTrue(strlen($process->getOutput()) > 0);
|
2012-03-21 16:58:02 +00:00
|
|
|
}
|
|
|
|
|
2013-08-20 19:22:08 +01:00
|
|
|
public function testGetExitCodeIsNullOnStart()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"');
|
2013-08-20 19:22:08 +01:00
|
|
|
$this->assertNull($process->getExitCode());
|
|
|
|
$process->start();
|
|
|
|
$this->assertNull($process->getExitCode());
|
|
|
|
$process->wait();
|
|
|
|
$this->assertEquals(0, $process->getExitCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetExitCodeIsNullOnWhenStartingAgain()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(200000);"');
|
2013-08-20 19:22:08 +01:00
|
|
|
$process->run();
|
|
|
|
$this->assertEquals(0, $process->getExitCode());
|
|
|
|
$process->start();
|
|
|
|
$this->assertNull($process->getExitCode());
|
|
|
|
$process->wait();
|
|
|
|
$this->assertEquals(0, $process->getExitCode());
|
|
|
|
}
|
|
|
|
|
2012-09-09 15:38:21 +01:00
|
|
|
public function testGetExitCode()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->run();
|
2014-03-10 15:55:29 +00:00
|
|
|
$this->assertSame(0, $process->getExitCode());
|
2012-09-09 15:38:21 +01:00
|
|
|
}
|
|
|
|
|
2012-10-27 17:54:34 +01:00
|
|
|
public function testStatus()
|
2012-03-23 11:59:10 +00:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2012-03-21 16:58:02 +00:00
|
|
|
$this->assertFalse($process->isRunning());
|
2012-10-27 17:54:34 +01:00
|
|
|
$this->assertFalse($process->isStarted());
|
|
|
|
$this->assertFalse($process->isTerminated());
|
|
|
|
$this->assertSame(Process::STATUS_READY, $process->getStatus());
|
2012-03-21 16:58:02 +00:00
|
|
|
$process->start();
|
|
|
|
$this->assertTrue($process->isRunning());
|
2012-10-27 17:54:34 +01:00
|
|
|
$this->assertTrue($process->isStarted());
|
|
|
|
$this->assertFalse($process->isTerminated());
|
|
|
|
$this->assertSame(Process::STATUS_STARTED, $process->getStatus());
|
2012-03-23 12:02:23 +00:00
|
|
|
$process->wait();
|
2012-03-21 16:58:02 +00:00
|
|
|
$this->assertFalse($process->isRunning());
|
2012-10-27 17:54:34 +01:00
|
|
|
$this->assertTrue($process->isStarted());
|
|
|
|
$this->assertTrue($process->isTerminated());
|
|
|
|
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
|
2012-03-21 16:58:02 +00:00
|
|
|
}
|
|
|
|
|
2012-03-23 11:59:10 +00:00
|
|
|
public function testStop()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
|
2012-03-21 16:58:02 +00:00
|
|
|
$process->start();
|
|
|
|
$this->assertTrue($process->isRunning());
|
|
|
|
$process->stop();
|
|
|
|
$this->assertFalse($process->isRunning());
|
2012-09-09 15:38:21 +01:00
|
|
|
}
|
2012-04-08 19:29:02 +01:00
|
|
|
|
2012-09-09 15:38:21 +01:00
|
|
|
public function testIsSuccessful()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->run();
|
|
|
|
$this->assertTrue($process->isSuccessful());
|
|
|
|
}
|
|
|
|
|
2013-08-21 15:50:47 +01:00
|
|
|
public function testIsSuccessfulOnlyAfterTerminated()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
|
2013-08-21 15:50:47 +01:00
|
|
|
$process->start();
|
|
|
|
while ($process->isRunning()) {
|
|
|
|
$this->assertFalse($process->isSuccessful());
|
|
|
|
usleep(300000);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($process->isSuccessful());
|
|
|
|
}
|
|
|
|
|
2012-09-09 15:38:21 +01:00
|
|
|
public function testIsNotSuccessful()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);throw new \Exception(\'BOUM\');"');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->start();
|
|
|
|
$this->assertTrue($process->isRunning());
|
2014-03-11 16:00:25 +00:00
|
|
|
$process->wait();
|
2012-09-09 15:38:21 +01:00
|
|
|
$this->assertFalse($process->isSuccessful());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProcessIsNotSignaled()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2012-09-09 15:38:21 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX signals');
|
2012-04-08 19:29:02 +01:00
|
|
|
}
|
2012-09-09 15:38:21 +01:00
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->run();
|
|
|
|
$this->assertFalse($process->hasBeenSignaled());
|
|
|
|
}
|
|
|
|
|
2012-09-09 15:56:43 +01:00
|
|
|
public function testProcessWithoutTermSignalIsNotSignaled()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2012-09-09 15:56:43 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX signals');
|
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:56:43 +01:00
|
|
|
$process->run();
|
|
|
|
$this->assertFalse($process->hasBeenSignaled());
|
|
|
|
}
|
|
|
|
|
2012-09-09 15:38:21 +01:00
|
|
|
public function testProcessWithoutTermSignal()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2012-09-09 15:38:21 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX signals');
|
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->run();
|
|
|
|
$this->assertEquals(0, $process->getTermSignal());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProcessIsSignaledIfStopped()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2012-09-09 15:38:21 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX signals');
|
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->start();
|
|
|
|
$process->stop();
|
|
|
|
$this->assertTrue($process->hasBeenSignaled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProcessWithTermSignal()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2012-09-09 15:38:21 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX signals');
|
|
|
|
}
|
|
|
|
|
2012-12-30 12:18:39 +00:00
|
|
|
// SIGTERM is only defined if pcntl extension is present
|
|
|
|
$termSignal = defined('SIGTERM') ? SIGTERM : 15;
|
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(4);"');
|
2012-09-09 15:38:21 +01:00
|
|
|
$process->start();
|
|
|
|
$process->stop();
|
2012-12-30 12:18:39 +00:00
|
|
|
|
|
|
|
$this->assertEquals($termSignal, $process->getTermSignal());
|
2012-03-21 16:58:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 11:07:05 +01:00
|
|
|
public function testProcessThrowsExceptionWhenExternallySignaled()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-04-29 11:07:05 +01:00
|
|
|
$this->markTestSkipped('Windows does not support POSIX signals');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('posix_kill')) {
|
|
|
|
$this->markTestSkipped('posix_kill is required for this test');
|
|
|
|
}
|
|
|
|
|
|
|
|
$termSignal = defined('SIGKILL') ? SIGKILL : 9;
|
|
|
|
|
|
|
|
$process = $this->getProcess('exec php -r "while (true) {}"');
|
|
|
|
$process->start();
|
|
|
|
posix_kill($process->getPid(), $termSignal);
|
|
|
|
|
2013-04-30 08:21:49 +01:00
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'The process has been signaled with signal "9".');
|
2013-04-29 11:07:05 +01:00
|
|
|
$process->wait();
|
|
|
|
}
|
|
|
|
|
2012-09-07 08:03:48 +01:00
|
|
|
public function testRestart()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process1 = $this->getProcess(self::$phpBin.' -r "echo getmypid();"');
|
2012-10-04 15:37:34 +01:00
|
|
|
$process1->run();
|
|
|
|
$process2 = $process1->restart();
|
2012-09-07 08:03:48 +01:00
|
|
|
|
2014-03-14 16:09:12 +00:00
|
|
|
$process2->wait(); // wait for output
|
2012-09-07 08:03:48 +01:00
|
|
|
|
2012-10-04 15:37:34 +01:00
|
|
|
// Ensure that both processed finished and the output is numeric
|
|
|
|
$this->assertFalse($process1->isRunning());
|
|
|
|
$this->assertFalse($process2->isRunning());
|
|
|
|
$this->assertTrue(is_numeric($process1->getOutput()));
|
|
|
|
$this->assertTrue(is_numeric($process2->getOutput()));
|
2012-09-07 08:03:48 +01:00
|
|
|
|
2012-10-04 15:37:34 +01:00
|
|
|
// Ensure that restart returned a new process by check that the output is different
|
|
|
|
$this->assertNotEquals($process1->getOutput(), $process2->getOutput());
|
2012-09-07 08:03:48 +01:00
|
|
|
}
|
|
|
|
|
2012-04-11 22:08:57 +01:00
|
|
|
public function testPhpDeadlock()
|
|
|
|
{
|
2014-08-28 10:02:24 +01:00
|
|
|
$this->markTestSkipped('Can cause PHP to hang');
|
2012-04-11 22:08:57 +01:00
|
|
|
|
2012-07-28 23:02:29 +01:00
|
|
|
// Sleep doesn't work as it will allow the process to handle signals and close
|
2012-04-11 22:08:57 +01:00
|
|
|
// file handles from the other end.
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "while (true) {}"');
|
2012-04-11 22:08:57 +01:00
|
|
|
$process->start();
|
|
|
|
|
|
|
|
// PHP will deadlock when it tries to cleanup $process
|
|
|
|
}
|
|
|
|
|
2013-04-06 19:51:55 +01:00
|
|
|
public function testRunProcessWithTimeout()
|
|
|
|
{
|
|
|
|
$timeout = 0.5;
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(600000);"');
|
2013-04-06 19:51:55 +01:00
|
|
|
$process->setTimeout($timeout);
|
|
|
|
$start = microtime(true);
|
|
|
|
try {
|
|
|
|
$process->run();
|
|
|
|
$this->fail('A RuntimeException should have been raised');
|
|
|
|
} catch (RuntimeException $e) {
|
|
|
|
}
|
|
|
|
$duration = microtime(true) - $start;
|
|
|
|
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2014-06-14 13:38:29 +01:00
|
|
|
// Windows is a bit slower as it read file handles, then allow twice the precision
|
|
|
|
$maxDuration = $timeout + 2 * Process::TIMEOUT_PRECISION;
|
|
|
|
} else {
|
|
|
|
$maxDuration = $timeout + Process::TIMEOUT_PRECISION;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertLessThan($maxDuration, $duration);
|
2013-04-06 19:51:55 +01:00
|
|
|
}
|
|
|
|
|
2014-03-18 15:17:31 +00:00
|
|
|
public function testCheckTimeoutOnNonStartedProcess()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
|
2014-03-18 15:17:31 +00:00
|
|
|
$process->checkTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckTimeoutOnTerminatedProcess()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2014-03-18 15:17:31 +00:00
|
|
|
$process->run();
|
|
|
|
$process->checkTimeout();
|
|
|
|
}
|
|
|
|
|
2013-04-06 19:51:55 +01:00
|
|
|
public function testCheckTimeoutOnStartedProcess()
|
|
|
|
{
|
|
|
|
$timeout = 0.5;
|
|
|
|
$precision = 100000;
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
|
2013-04-06 19:51:55 +01:00
|
|
|
$process->setTimeout($timeout);
|
|
|
|
$start = microtime(true);
|
|
|
|
|
|
|
|
$process->start();
|
|
|
|
|
|
|
|
try {
|
|
|
|
while ($process->isRunning()) {
|
|
|
|
$process->checkTimeout();
|
|
|
|
usleep($precision);
|
|
|
|
}
|
|
|
|
$this->fail('A RuntimeException should have been raised');
|
|
|
|
} catch (RuntimeException $e) {
|
|
|
|
}
|
|
|
|
$duration = microtime(true) - $start;
|
|
|
|
|
|
|
|
$this->assertLessThan($timeout + $precision, $duration);
|
2013-08-14 16:41:18 +01:00
|
|
|
$this->assertFalse($process->isSuccessful());
|
2013-04-06 19:51:55 +01:00
|
|
|
}
|
|
|
|
|
2013-08-02 20:20:26 +01:00
|
|
|
public function testIdleTimeout()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
|
2013-08-02 20:20:26 +01:00
|
|
|
$process->setTimeout(10);
|
2014-03-14 18:10:30 +00:00
|
|
|
$process->setIdleTimeout(0.5);
|
2013-08-02 20:20:26 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$process->run();
|
|
|
|
|
|
|
|
$this->fail('A timeout exception was expected.');
|
|
|
|
} catch (ProcessTimedOutException $ex) {
|
|
|
|
$this->assertTrue($ex->isIdleTimeout());
|
|
|
|
$this->assertFalse($ex->isGeneralTimeout());
|
2014-03-14 18:10:30 +00:00
|
|
|
$this->assertEquals(0.5, $ex->getExceededTimeout());
|
2013-08-02 20:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIdleTimeoutNotExceededWhenOutputIsSent()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 30; while ($n--) {echo "foo\n"; usleep(100000); }')));
|
2014-03-14 18:10:30 +00:00
|
|
|
$process->setTimeout(2);
|
2015-04-07 12:59:04 +01:00
|
|
|
$process->setIdleTimeout(1);
|
2013-08-02 20:20:26 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$process->run();
|
|
|
|
$this->fail('A timeout exception was expected.');
|
|
|
|
} catch (ProcessTimedOutException $ex) {
|
2015-04-07 12:59:04 +01:00
|
|
|
$this->assertTrue($ex->isGeneralTimeout(), 'A general timeout is expected.');
|
|
|
|
$this->assertFalse($ex->isIdleTimeout(), 'No idle timeout is expected.');
|
2014-03-14 18:10:30 +00:00
|
|
|
$this->assertEquals(2, $ex->getExceededTimeout());
|
2013-08-02 20:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-16 12:32:46 +01:00
|
|
|
public function testStartAfterATimeout()
|
|
|
|
{
|
2015-06-30 17:05:31 +01:00
|
|
|
$process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 1000; while ($n--) {echo \'\'; usleep(1000); }')));
|
2013-09-16 12:32:46 +01:00
|
|
|
$process->setTimeout(0.1);
|
2014-03-26 11:51:10 +00:00
|
|
|
|
2013-09-16 12:32:46 +01:00
|
|
|
try {
|
|
|
|
$process->run();
|
2015-01-19 13:26:55 +00:00
|
|
|
$this->fail('A RuntimeException should have been raised.');
|
|
|
|
} catch (RuntimeException $e) {
|
2013-09-16 12:32:46 +01:00
|
|
|
}
|
|
|
|
$process->start();
|
2014-03-14 18:10:30 +00:00
|
|
|
usleep(1000);
|
2013-09-16 12:32:46 +01:00
|
|
|
$process->stop();
|
|
|
|
}
|
|
|
|
|
2012-09-09 15:56:43 +01:00
|
|
|
public function testGetPid()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2012-09-09 15:56:43 +01:00
|
|
|
$process->start();
|
|
|
|
$this->assertGreaterThan(0, $process->getPid());
|
2014-03-11 16:00:25 +00:00
|
|
|
$process->wait();
|
2012-09-09 15:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPidIsNullBeforeStart()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
|
2012-09-09 15:56:43 +01:00
|
|
|
$this->assertNull($process->getPid());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPidIsNullAfterRun()
|
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2012-09-09 15:56:43 +01:00
|
|
|
$process->run();
|
|
|
|
$this->assertNull($process->getPid());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSignal()
|
|
|
|
{
|
2013-06-13 20:00:58 +01:00
|
|
|
$this->verifyPosixIsEnabled();
|
2013-04-25 14:23:11 +01:00
|
|
|
|
2014-09-21 19:53:12 +01:00
|
|
|
$process = $this->getProcess('exec php -f '.__DIR__.'/SignalListener.php');
|
2012-09-09 15:56:43 +01:00
|
|
|
$process->start();
|
|
|
|
usleep(500000);
|
|
|
|
$process->signal(SIGUSR1);
|
|
|
|
|
2014-09-22 23:14:46 +01:00
|
|
|
while ($process->isRunning() && false === strpos($process->getOutput(), 'Caught SIGUSR1')) {
|
2012-09-09 15:56:43 +01:00
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals('Caught SIGUSR1', $process->getOutput());
|
|
|
|
}
|
|
|
|
|
2013-08-13 19:21:22 +01:00
|
|
|
public function testExitCodeIsAvailableAfterSignal()
|
|
|
|
{
|
|
|
|
$this->verifyPosixIsEnabled();
|
|
|
|
|
|
|
|
$process = $this->getProcess('sleep 4');
|
|
|
|
$process->start();
|
|
|
|
$process->signal(SIGKILL);
|
|
|
|
|
|
|
|
while ($process->isRunning()) {
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertFalse($process->isRunning());
|
|
|
|
$this->assertTrue($process->hasBeenSignaled());
|
|
|
|
$this->assertFalse($process->isSuccessful());
|
|
|
|
$this->assertEquals(137, $process->getExitCode());
|
|
|
|
}
|
|
|
|
|
2012-09-09 15:56:43 +01:00
|
|
|
/**
|
2013-11-25 14:52:16 +00:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\LogicException
|
2012-09-09 15:56:43 +01:00
|
|
|
*/
|
|
|
|
public function testSignalProcessNotRunning()
|
2013-06-13 20:00:58 +01:00
|
|
|
{
|
|
|
|
$this->verifyPosixIsEnabled();
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2013-06-13 20:00:58 +01:00
|
|
|
$process->signal(SIGHUP);
|
|
|
|
}
|
|
|
|
|
2013-11-05 22:13:55 +00:00
|
|
|
/**
|
2014-03-18 15:17:31 +00:00
|
|
|
* @dataProvider provideMethodsThatNeedARunningProcess
|
2013-11-05 22:13:55 +00:00
|
|
|
*/
|
2014-03-18 15:17:31 +00:00
|
|
|
public function testMethodsThatNeedARunningProcess($method)
|
2013-11-05 22:13:55 +00:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -v');
|
2014-03-18 15:17:31 +00:00
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
|
2014-11-21 08:49:35 +00:00
|
|
|
$process->{$method}();
|
2013-11-05 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 15:17:31 +00:00
|
|
|
public function provideMethodsThatNeedARunningProcess()
|
2013-11-05 22:13:55 +00:00
|
|
|
{
|
2014-03-18 15:17:31 +00:00
|
|
|
return array(
|
|
|
|
array('getOutput'),
|
|
|
|
array('getIncrementalOutput'),
|
|
|
|
array('getErrorOutput'),
|
|
|
|
array('getIncrementalErrorOutput'),
|
|
|
|
array('wait'),
|
|
|
|
);
|
2013-11-05 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-18 15:17:31 +00:00
|
|
|
* @dataProvider provideMethodsThatNeedATerminatedProcess
|
2013-11-05 22:13:55 +00:00
|
|
|
*/
|
2014-03-18 15:17:31 +00:00
|
|
|
public function testMethodsThatNeedATerminatedProcess($method)
|
2013-11-05 22:13:55 +00:00
|
|
|
{
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
|
2014-03-18 15:17:31 +00:00
|
|
|
$process->start();
|
|
|
|
try {
|
2014-11-21 08:49:35 +00:00
|
|
|
$process->{$method}();
|
2014-03-18 15:17:31 +00:00
|
|
|
$process->stop(0);
|
|
|
|
$this->fail('A LogicException must have been thrown');
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->assertInstanceOf('Symfony\Component\Process\Exception\LogicException', $e);
|
|
|
|
$this->assertEquals(sprintf('Process must be terminated before calling %s.', $method), $e->getMessage());
|
|
|
|
}
|
|
|
|
$process->stop(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideMethodsThatNeedATerminatedProcess()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('hasBeenSignaled'),
|
|
|
|
array('getTermSignal'),
|
|
|
|
array('hasBeenStopped'),
|
|
|
|
array('getStopSignal'),
|
|
|
|
);
|
2013-11-05 22:13:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 20:00:58 +01:00
|
|
|
private function verifyPosixIsEnabled()
|
2012-09-09 15:56:43 +01:00
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-12-27 15:08:19 +00:00
|
|
|
$this->markTestSkipped('POSIX signals do not work on Windows');
|
2013-04-25 14:23:11 +01:00
|
|
|
}
|
2013-06-13 20:00:58 +01:00
|
|
|
if (!defined('SIGUSR1')) {
|
|
|
|
$this->markTestSkipped('The pcntl extension is not enabled');
|
|
|
|
}
|
2012-09-09 15:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-25 14:52:16 +00:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
|
2012-09-09 15:56:43 +01:00
|
|
|
*/
|
|
|
|
public function testSignalWithWrongIntSignal()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-12-27 15:08:19 +00:00
|
|
|
$this->markTestSkipped('POSIX signals do not work on Windows');
|
2013-04-25 14:23:11 +01:00
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
|
2012-09-09 15:56:43 +01:00
|
|
|
$process->start();
|
|
|
|
$process->signal(-4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-25 14:52:16 +00:00
|
|
|
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
|
2012-09-09 15:56:43 +01:00
|
|
|
*/
|
|
|
|
public function testSignalWithWrongNonIntSignal()
|
|
|
|
{
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-12-27 15:08:19 +00:00
|
|
|
$this->markTestSkipped('POSIX signals do not work on Windows');
|
2013-04-25 14:23:11 +01:00
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:58 +01:00
|
|
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(3);"');
|
2012-09-09 15:56:43 +01:00
|
|
|
$process->start();
|
|
|
|
$process->signal('Céphalopodes');
|
|
|
|
}
|
|
|
|
|
2013-12-11 18:23:45 +00:00
|
|
|
public function testDisableOutputDisablesTheOutput()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2013-12-11 18:23:45 +00:00
|
|
|
$this->assertFalse($p->isOutputDisabled());
|
|
|
|
$p->disableOutput();
|
|
|
|
$this->assertTrue($p->isOutputDisabled());
|
|
|
|
$p->enableOutput();
|
|
|
|
$this->assertFalse($p->isOutputDisabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisableOutputWhileRunningThrowsException()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2013-12-11 18:23:45 +00:00
|
|
|
$p->start();
|
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Disabling output while the process is running is not possible.');
|
|
|
|
$p->disableOutput();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnableOutputWhileRunningThrowsException()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2013-12-11 18:23:45 +00:00
|
|
|
$p->disableOutput();
|
|
|
|
$p->start();
|
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'Enabling output while the process is running is not possible.');
|
|
|
|
$p->enableOutput();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnableOrDisableOutputAfterRunDoesNotThrowException()
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2013-12-11 18:23:45 +00:00
|
|
|
$p->disableOutput();
|
|
|
|
$p->start();
|
|
|
|
$p->wait();
|
|
|
|
$p->enableOutput();
|
|
|
|
$p->disableOutput();
|
|
|
|
}
|
|
|
|
|
2014-03-14 18:08:20 +00:00
|
|
|
public function testDisableOutputWhileIdleTimeoutIsSet()
|
|
|
|
{
|
|
|
|
$process = $this->getProcess('sleep 3');
|
|
|
|
$process->setIdleTimeout(1);
|
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output can not be disabled while an idle timeout is set.');
|
|
|
|
$process->disableOutput();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetIdleTimeoutWhileOutputIsDisabled()
|
|
|
|
{
|
|
|
|
$process = $this->getProcess('sleep 3');
|
|
|
|
$process->disableOutput();
|
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Idle timeout can not be set while the output is disabled.');
|
|
|
|
$process->setIdleTimeout(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetNullIdleTimeoutWhileOutputIsDisabled()
|
|
|
|
{
|
|
|
|
$process = $this->getProcess('sleep 3');
|
|
|
|
$process->disableOutput();
|
|
|
|
$process->setIdleTimeout(null);
|
|
|
|
}
|
|
|
|
|
2013-12-11 18:23:45 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideStartMethods
|
|
|
|
*/
|
2014-08-28 17:24:17 +01:00
|
|
|
public function testStartWithACallbackAndDisabledOutput($startMethod, $exception, $exceptionMessage)
|
2013-12-11 18:23:45 +00:00
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2013-12-11 18:23:45 +00:00
|
|
|
$p->disableOutput();
|
2014-08-28 17:24:17 +01:00
|
|
|
$this->setExpectedException($exception, $exceptionMessage);
|
2014-11-21 09:14:57 +00:00
|
|
|
$p->{$startMethod}(function () {});
|
2013-12-11 18:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideStartMethods()
|
|
|
|
{
|
|
|
|
return array(
|
2014-08-28 17:24:17 +01:00
|
|
|
array('start', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'),
|
|
|
|
array('run', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'),
|
|
|
|
array('mustRun', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'),
|
2013-12-11 18:23:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideOutputFetchingMethods
|
|
|
|
*/
|
|
|
|
public function testGetOutputWhileDisabled($fetchMethod)
|
|
|
|
{
|
2015-06-30 17:10:16 +01:00
|
|
|
$p = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
|
2013-12-11 18:23:45 +00:00
|
|
|
$p->disableOutput();
|
2014-03-26 11:51:10 +00:00
|
|
|
$p->start();
|
2013-12-11 18:23:45 +00:00
|
|
|
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output has been disabled.');
|
2014-11-21 09:14:57 +00:00
|
|
|
$p->{$fetchMethod}();
|
2013-12-11 18:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideOutputFetchingMethods()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('getOutput'),
|
|
|
|
array('getIncrementalOutput'),
|
|
|
|
array('getErrorOutput'),
|
|
|
|
array('getIncrementalErrorOutput'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-06-22 20:47:44 +01:00
|
|
|
public function responsesCodeProvider()
|
2011-05-09 21:40:18 +01:00
|
|
|
{
|
|
|
|
return array(
|
|
|
|
//expected output / getter / code to execute
|
|
|
|
//array(1,'getExitCode','exit(1);'),
|
|
|
|
//array(true,'isSuccessful','exit();'),
|
2011-07-23 17:04:56 +01:00
|
|
|
array('output', 'getOutput', 'echo \'output\';'),
|
2011-06-22 20:47:44 +01:00
|
|
|
);
|
|
|
|
}
|
2011-06-23 12:39:36 +01:00
|
|
|
|
2011-06-22 20:47:44 +01:00
|
|
|
public function pipesCodeProvider()
|
|
|
|
{
|
|
|
|
$variations = array(
|
2011-07-23 17:04:56 +01:00
|
|
|
'fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);',
|
2013-09-10 17:39:36 +01:00
|
|
|
'include \''.__DIR__.'/PipeStdinInStdoutStdErrStreamSelect.php\';',
|
2011-05-09 21:40:18 +01:00
|
|
|
);
|
2011-06-22 20:47:44 +01:00
|
|
|
|
2014-12-29 12:05:07 +00:00
|
|
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
2013-09-10 17:39:36 +01:00
|
|
|
// Avoid XL buffers on Windows because of https://bugs.php.net/bug.php?id=65650
|
|
|
|
$sizes = array(1, 2, 4, 8);
|
|
|
|
} else {
|
|
|
|
$sizes = array(1, 16, 64, 1024, 4096);
|
|
|
|
}
|
|
|
|
|
2011-06-22 20:47:44 +01:00
|
|
|
$codes = array();
|
2013-09-10 17:39:36 +01:00
|
|
|
foreach ($sizes as $size) {
|
2011-06-22 20:47:44 +01:00
|
|
|
foreach ($variations as $code) {
|
2013-05-06 10:50:13 +01:00
|
|
|
$codes[] = array($code, $size);
|
2011-06-22 20:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
2011-06-23 12:39:36 +01:00
|
|
|
|
2011-06-22 20:47:44 +01:00
|
|
|
return $codes;
|
2011-05-09 21:40:18 +01:00
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* provides default method names for simple getter/setter.
|
2011-05-09 21:40:18 +01:00
|
|
|
*/
|
|
|
|
public function methodProvider()
|
|
|
|
{
|
|
|
|
$defaults = array(
|
|
|
|
array('CommandLine'),
|
|
|
|
array('Timeout'),
|
|
|
|
array('WorkingDirectory'),
|
|
|
|
array('Env'),
|
|
|
|
array('Stdin'),
|
2014-05-17 19:36:38 +01:00
|
|
|
array('Input'),
|
2014-09-21 19:53:12 +01:00
|
|
|
array('Options'),
|
2011-05-09 21:40:18 +01:00
|
|
|
);
|
2011-06-08 18:56:59 +01:00
|
|
|
|
2011-05-09 21:40:18 +01:00
|
|
|
return $defaults;
|
|
|
|
}
|
2013-01-08 19:11:30 +00:00
|
|
|
|
|
|
|
/**
|
2014-12-02 20:15:53 +00:00
|
|
|
* @param string $commandline
|
|
|
|
* @param null|string $cwd
|
|
|
|
* @param null|array $env
|
|
|
|
* @param null|string $input
|
|
|
|
* @param int $timeout
|
|
|
|
* @param array $options
|
2013-01-08 19:11:30 +00:00
|
|
|
*
|
2013-01-16 09:27:54 +00:00
|
|
|
* @return Process
|
2013-01-08 19:11:30 +00:00
|
|
|
*/
|
2014-05-17 19:36:38 +01:00
|
|
|
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array());
|
2011-05-09 21:40:18 +01:00
|
|
|
}
|
2014-05-17 18:27:19 +01:00
|
|
|
|
|
|
|
class Stringifiable
|
|
|
|
{
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return 'stringifiable';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NonStringifiable
|
|
|
|
{
|
|
|
|
}
|